Why Host Your Own Site?
C HANGING NIC S PEED AND D UPLE
There is no better Linux investment than the purchase of a fully Linux-com- patible NIC card. Most Linux vendors have a list of compatible hardware on their Web sites; read this carefully before you start hooking up your machine to the network. If you can’t find any of the desired models in your local com- puter store, a model in the same family or series should be sufficient. Most cards will work, but only the fully compatible ones will provide you with error- free, consistent throughput.
Linux defaults to negotiating the speed and duplex of its NIC automati- cally with that of the switch to which it is attached. Configuring a switch port to autonegotiate the speed and duplex often isn’t sufficient because there are frequently differences in the implementation of the protocol standard.
Typically, NICs with failed negotiation will work, but this is usually accompanied by many collision-type errors being seen on the NIC, when using the ifconfig -a command, and only marginal performance. Don’t limit your
troubleshooting of these types of errors to just failed negotiation; the problem could also be due to a bad NIC card, switch port, or cabling.
Using mii-tool
One of the original Linux tools for setting the speed and duplex of your NIC card was the mii-toolcommand. It is destined to be deprecated and replaced
by the newer ethtoolcommand, but many older NICs support only mii-tool, so
you need to be aware of it.
Issuing the command without any arguments gives a brief status report, as seen in the next example, with unsupported NICs providing an Operation not supportedmessage. NICs that are not compatible with mii-tooloften will
still work, but you have to refer to the manufacturer’s guides to set the speed and duplex to anything but auto-negotiate.
Changing NIC Speed and Duplex 49
[root@bigboy tmp]# mii-tool
SIOCGMIIPHY on ‘eth0’ failed: Operation not supported eth1: 100 Mbit, half duplex, link ok
[root@bigboy tmp]#
By using the verbose mode -vswitch you can get much more information.
In this case, negotiation was OK, with the NIC selecting 100Mbps, full duplex mode (FD):
[root@bigboy tmp]# mii-tool -v
eth1: negotiated 100baseTx-FD, link ok
product info: vendor 00:10:18, model 33 rev 2 basic mode: autonegotiation enabled
basic status: autonegotiation complete, link ok
capabilities: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD advertising: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD link partner: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow- control
[root@bigboy tmp]#
Setting Your NIC’s Speed Parameters with mii-tool
You can set your NIC to force itself to a particular speed and duplex by using the -Fswitch with any of the following options: 100baseTx-FD, 100baseTx-HD,
10baseT-FD, or 10baseT-HD. Remember that you could lose all network con- nectivity to your server if you force your NIC to a particular speed/duplex that doesn’t match that of your switch:
[root@bigboy tmp]# mii-tool -F 100baseTx-FD eth0
Unfortunately there is no way to set this on reboot permanently except by placing the command in the /etc/rc.localfile to let it be run at the very
end of the booting process or by creating your own startup script if you need it set earlier. Creating your own startup scripts is covered in Chapter 7, “The Linux Boot Process.”
Using ethtool
The ethtoolcommand is slated to be the replacement for mii-toolin the near
future and tends to be supported by newer NIC cards.
The command provides the status of the interface you provide as its argument. Here we see interface eth0 not doing autonegotiation and set to a
speed of 100Mbps, full duplex. A list of supported modes is also provided at the top of the output:
[root@bigboy tmp]# ethtool eth0 Settings for eth0:
50 Linux Networking Chapter 3
Supported ports: [ TP MII ]
Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full Advertised auto-negotiation: No Speed: 100Mb/s Duplex: Full Port: MII PHYAD: 1 Transceiver: internal Auto-negotiation: off Supports Wake-on: g Wake-on: g
Current message level: 0x00000007 (7) Link detected: yes
[root@bigboy tmp]#
Setting Your NIC’s Speed Parameters with ethtool
Unlike mii-tool,ethtoolsettings can be permanently set as part of the inter-
face’s configuration script with the ETHTOOL_OPTSvariable. In our next example,
the settings will be set to 100Mbps, full duplex with no chance for autonegoti- ation on the next reboot:
# # File: /etc/sysconfig/network-script/ifcfg-eth0 # DEVICE=eth0 IPADDR=192.168.1.100 NETMASK=255.255.255.0 BOOTPROTO=static ONBOOT=yes
ETHTOOL_OPTS = “speed 100 duplex full autoneg off”
You can test the application of these parameters by shutting down the interface and activating it again with the ifupand ifdowncommands.
These settings can also be changed from the command line using the -s
switch followed by the interface name and its desired configuration parameters.
[root@bigboy tmp]# ethtool -s eth1 speed 100 duplex full autoneg off [root@bigboy tmp]#
The Linux manpages give more details on other ethtooloptions, but you
can get a quick guide by just entering the ethtoolcommand alone, which pro-
vides a quicker summary:
[root@bigboy tmp]# ethtool ...
...
Changing NIC Speed and Duplex 51
ethtool -s DEVNAME \ [ speed 10|100|1000 ] \ [ duplex half|full ] \ [ port tp|aui|bnc|mii|fibre ] \ ... ... [root@bigboy tmp]#