Getting Linux Connected, using Ethernet and TCP/IP

Configuring these settings the hardway - in the scripts


The first way to configure the IP address, subnet mask and option default gateway address is in the system boot scripts.

The location of these scripts is Linux distribution dependent, but the are usually located somewhere under the /etc subdirectory.

For example, under the slackware distribution, they are located in the /etc/rc.d subdirectory.

rc.inet1

The rc.inet1 file is the location of the commands which assign an IP address, subnetmask and default gateway to the Linux box.

Assigning an IP address and subnet mask to eth0

Somewhere within the rc.inet1 script will be the lines which assign an IP address and subnet mask to the eth0 interface.

These lines will look something like this :

/sbin/ifconfig eth0 10.0.1.65 netmask 255.255.255.0 broadcast 10.0.1.255
/sbin/route add -net 10.0.1.0 dev eth0 netmask 255.255.255.0

The first line assigns an IP address of 10.0.1.65 to the eth0 interface. It also specifies the subnet mask (netmask 255.255.255.0) and also sets the interface broadcast value, which corresponds to the network and subnet number, with a host address of all binary 1s (broadcast 10.0.1.255).

The second line adds an entry into the route table, specifying that the 10.0.1.0 subnet is attached to the eth0 device. Ensure that you assign the subnet number to the eth0 interface, by specifying the network and subnet, with a host address of all binary 0s (10.0.1.0).

Assigning the Default Gateway Address

Remember that you may not assign a Default Gateway address, if you have no gateways, or you are using PPP.

If you do need to assign a default gateway address, there will be a line in the rc.inet1 file which looks like this :

/sbin/route add default gw 10.0.1.1

This line assigns a default gateway address of 10.0.1.1. Specify the value of your default gateway instead of 10.0.1.1.

Applying these settings

After you have changed and saved the rc.inet1 script, you need to apply these settings.

Although you could run the script manually, it is best to reboot the Linux box to ensure that the settings will be applied automatically, every time Linux is booted.

Checking the settings

IP Address and Subnet Mask

To check the IP address and subnet mask settings for your ethernet card issue the following command :

/sbin/ifconfig eth0

The values you are interested in are the inet addr which should correspond to the IP address you assigned, the Bcast address, which should correspond to the broadcast address you assigned, and finaly, the Mask value, which should correspond to the subnet mask you assigned.

Default Gateway

To check the default gateway value issue the following command :

netstat -rn

This command shows the route table of the Linux box, which is where the default gateway value is stored.

Look for the entry which has 0.0.0.0 in the destination column. Under the Gateway column of the same row, you should see the IP address you specified as the default gateway address.

You may also notice that you have an entry with a destination of the subnet you assigned to the eth0 interface. This is the result of the second command (route) configured when setting the IP address of the eth0 interface.


[Previous Page] | [Next Page] | [Start of Current Topic] | [Previous Topic] | [Next Topic]

LinuxSA - http://www.linuxsa.org.au

Prepared by Mark Smith
marks@senet.com.au

Fri Feb 20 13:28:08 CST 1998