To assign an IP address to a LAN adapter, the ifconfig command is used. This command is also used to display the IP address assigned to an adapter. For example, the following command shows an IP address assigned to lan0 .
# ifconfig lan0 lan0: flags=843<UP,BROADCAST,RUNNING,MULTICAST> inet 192.168.2.11 netmask ffffff00 broadcast 192.168.2.255 #
To configure interface lan2 with IP address 192.168.3.1, use the following command.
ifconfig lan2 192.168.3.1 netmask 255.255.255.0 broadcast 192.168.3.255 up
The netmask keyword is used to specify a netmask with the IP address. Netmask is used for subnetting. A broadcast keyword is used to set the broadcast address for the interface. Now if you display the interface with the following command, it shows the configuration just assigned to it.
# ifconfig lan2 lan2: flags=843<UP,BROADCAST,RUNNING,MULTICAST> inet 192.168.3.1 netmask ffffff00 broadcast 192.168.3.255 #
A configuration that was created using the ifconfig command will be finished if you reboot the system. It means you need to execute the ifconfig command at system startup time. This is done through the execution of the /sbin/init.d/net script at run level 2. This script reads configuration information from the /etc/rc.config.d/netconf file. This configuration file keeps information of IP addresses assigned to each network interface. At system boot time, this information is used to configure LAN adapters. Typical entries in the configuration file for the two configured interfaces are shown next . The first two lines show the IP address and netmask, while the third line contains the name of the interface to which this address is assigned. Square brackets in every line enclose the reference number used for all entries related to one LAN adapter. The number 0 is used for all lines related to lan0 , and the number 2 is used for all lines related to lan2 .
IP_ADDRESS[0]=192.168.2.11 SUBNET_MASK[0]=255.255.255.0 INTERFACE_NAME[0]=lan0 BROADCAST_ADDRESS[0]=192.168.2.255 INTERFACE_STATE[0]=up ROUTE_GATEWAY[0]=192.168.2.1 ROUTE_COUNT[0]=1 ROUTE_DESTINATION[0]=default DHCP_ENABLE[0]=0 IP_ADDRESS[2]=192.168.3.1 SUBNET_MASK[2]=255.255.255.0 INTERFACE_NAME[2]=lan2 BROADCAST_ADDRESS[2]=192.168.3.255 INTERFACE_STATE[2]=up
If you are not using SAM, you have to manually create these entries for every LAN adapter.
After assigning IP addresses with the ifconfig command, you can use the netstat command to verify that the network interfaces are up and correct addresses are assigned to them.
# netstat -in Name Mtu Network Address Ipkts Opkts lan2 1500 192.168.3.0 192.168.3.1 0 0 lan0 1500 192.168.2.0 192.168.2.11 31740 32864 lo0 4136 127.0.0.0 127.0.0.1 303 303 #
You can also assign multiple IP addresses to one physical network adapter. This may be needed if you want to run different services using unique IP addresses. To assign a second IP address, you add a logical instance number to a LAN adapter name. It is a number that is added to the NamePPA (e.g., lan2 ) after a colon . The following command adds a second IP address, 192.168.3.5, to lan2 .
ifconfig lan2:1 192.168.3.5 netmask 255.255.255.0 broadcast 192.168.3.255 up
After assigning the second IP address, you can use the netstat command to verify it. To make the second address permanent, you have to add its configuration the /etc/rc.config.d/netconf file.
# netstat -in Name Mtu Network Address Ipkts Opkts lan2 1500 192.168.3.0 192.168.3.1 0 0 lan0 1500 192.168.2.0 192.168.2.11 31740 32864 lo0 4136 127.0.0.0 127.0.0.1 303 303 lan2:1 1500 192.168.3.0 192.168.3.5 0 0 #
After assigning an IP address to a network adapter, you should add one or more aliases for that IP address in the /etc/hosts file. These aliases are arbitrary names used to refer to the adapter's IP address. In this case, the host name is myhp , which is linked to IP address 192.168.2.11. When we configure a second adapter, we can add an alias hp0 with it. The resulting /etc/hosts file looks like the following.
## Configured using SAM by root on Fri Dec 3 12:30:36 1999 # @(#)hosts $Revision: 1.9.14.1 $ $Date: 96/10/08 13:20:01 $ # # The form for each entry is: # <internet address> <official hostname> <aliases> # # For example: # 192.1.2.34 hpfcrm loghost # # See the hosts(4) manual page for more information. # Note: The entries cannot be preceded by a space. # The format described in this file is the correct format. # The original Berkeley manual page contains an error in # the format description. # 192.168.3.1 myhp hp0 192.168.2.11 myhp myhp 127.0.0.1 localhost loopback
If you are using SAM, this file is automatically updated. More information about this file will be presented in Chapter 34 where name resolution is discussed.
Top |