Configure a Network Interface


ifconfig

In the first section of this chapter, "View the Status of Your Network Interfaces," you saw how you could use ifconfig to get details about the status of your network interfaces. The ifconfig command is more powerful than that, however, as you can also use it to configure your network interfaces.

Note

You can make quite a few changes with ifconfig, but you're only going to look at a few (for more details, see man ifconfig).


To change the IP address for the Ethernet card found at eth0 to 192.168.0.125, run this command (virtually all commands associated with ifconfig need to be run as root):

# ifconfig eth0 192.168.0.125 


In order to run certain types of network-sniffing tools, such as the awesome Ethereal, you first need to set your network card to promiscuous mode. By default, eth0 only listens for packets sent specifically to it, but in order to sniff all the packets flowing by on a network, you need to tell your card to listen to everything, which is promiscuous mode.

# ifconfig eth0 promisc 


After you've done that, running ifconfig shows you that your card is now looking at every packet it can. See the PROMISC in the fourth line?

# ifconfig eth0 eth0 Link encap:Ethernet  HWaddr 00:02:8A:36:48:8A  inet addr:192.168.0.143  Bcast:192.168.0.255   Mask:255.255.255.0  inet6 addr: fe80::202:8aff:fe36:488a/64 Scope:Link  UP BROADCAST PROMISC MULTICAST MTU:1500 Metric:1 [Results truncated for length] 


When you're done using Ethereal, don't forget to turn off promiscuous mode.

# ifconfig eth0 -promisc # ifconfig eth0 eth0 Link encap:Ethernet  HWaddr 00:02:8A:36:48:8A inet addr:192.168.0.143  Bcast:192.168.0.255   Mask:255.255.255.0 inet6 addr: fe80::202:8aff:fe36:488a/64 Scope:Link UP BROADCAST MULTICAST  MTU:1500  Metric:1 


You can even change (or "spoof") the hardware MAC address for your network device. This is usually only necessary to get around some ISPs' attempts to link Internet service to a specific machine. Be careful with spoofing your MAC address because a mistake can conflict with other network devices, causing problems. If you do decide to spoof your MAC, make sure you use ifconfig by itself to first acquire the default MAC address so you can roll back to that later (by the way, the MAC address shown in this command is completely bogus, so don't try to use it).

# ifconfig eth0 hw ether 00:14:CC:00:1A:00 


The ifconfig command is a cornerstone of working with network interfaces. Make sure you understand how it works so you can take maximum advantage of all it has to offer.



Linux Phrasebook
Linux Phrasebook
ISBN: 0672328380
EAN: 2147483647
Year: 2007
Pages: 288

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net