# route add default gw 149.112.50.65
Note that you could use a hostname rather than an IP address if desired. Another common use is to add the network to the routing table right after using the ifconfig command to configure the interface. Assuming that the 208.59.243.0 entry from the previous examples was missing, replace it using the following command:
# route add -net 208.59.243.0 netmask 255.255.255.0 dev eth0
You also can use /sbin/route to configure a specific host for a direct (point-to-point) connection. For example, suppose that you have a home network of two computers. One of the computers has a modem through which it connects to your business network. You typically work at the other computer. You can use the route command to establish a connection through specific hosts by using the following command:
# route add -host 198.135.62.25 gw 149.112.50.65
The preceding example makes the computer with the modem the gateway for the computer you are using. This type of command line is useful if you have a gateway or fire wall connected to the Internet. There are many additional uses for the route command, such as manipulating the default packet size. See the man page for those uses.
/bin/netstatThe netstat command is used to display the status of your network. It has several para meters that can display as much or as little information as you prefer. The services are listed by sockets (application-to-application connections between two computers). You can use netstat to display the information in Table 14.2.
TABLE 14.2 netstat Options
| Option | Output |
|---|---|
-g |
Displays the multicast groups configured |
-i |
Displays the interfaces configured by ifconfig |
-s |
Lists a summary of activity for each protocol |
-v |
Gives verbose output, listing both active and inactive sockets |
-c |
Updates output every second (good for testing and troubleshooting) |
-e |
Gives verbose output for active connections only |
-C |
Displays information from the route cache and is good for looking at past connections |
Several other options are available for this command, but they are used less often. As with the /sbin/route command, the man page can give you details about all options and para meters.
Network Configuration Files
As previously stated, seven network configuration files can be modified to make changes to basic network interaction of your system. The files are as follows:
► /etc/hosts — A listing of addresses, hostnames, and aliases
► /etc/services — Network service and port connections
► /etc/nsswitch.conf — Linux network information service configuration
► /etc/resolv.conf — Domain name service domain (search) settings
► /etc/host.conf — Network information search order (by default, /etc/hosts and then DNS)
► /etc/sysconfig/network — The hostname, IP address, boot activation control, and gateway settings (along with optional IPv6 settings)
► /etc/sysconfig/network-scripts/ifcfg-eth0 — Network settings for the eth0 network device; see the file sysconfig.txt under the /usr/share/doc/initscripts/ directory for details about optional settings
After the first six of these files have been modified, the changes are active. As with most configuration files, comments can be added with a hash mark (#) preceding the comment. The last file (/etc/sysconfig/network) requires the networking daemons to be restarted before the file is used. All seven of these files have a man page written about them for more information.
/etc/hostsThe /etc/hosts file is a map of IP to hostnames. If you are not using DNS or another naming service, and you are connected to a large network, this file can get quite large and can be a real headache to manage. A small /etc/hosts file can look something like this:
127.0.0.1 localhost.localdomain localhost
128.112.50.69 myhost.mydomain.com myhost
128.112.50.169 yourhost.mydomain.com yourhost
The first entry is for the loopback entry. The second is for the name of the machine. The third is another machine on the network. If no naming service is in use on the network, the only host that myhost recognizes by name is yourhost. (IP addresses on the network can still be used.)
If your network is using a naming service, the last line is not needed and can be deleted. However, if myhost connects to yourhost frequently, it might be good to leave the entry so that myhost does not need to consult the naming service each time. This can save time and reduce the strain on the network or the name service server. Edit this file if you need to change your hostname or IP address or if you aren't using a naming service and a host has been added to your network.
/etc/servicesThe /etc/services file maps port numbers to services. The first few lines look similar to this (the /etc/services file can be quite long, more than 500 lines):
# Each line describes one service, and is of the form:
#
# service-name port/protocol [aliases ... ] [# comment]
tcpmux 1/tcp # TCP port service multiplexer
tcpmux 1/udp # TCP port service multiplexer
rje 5/tcp # Remote Job Entry
rje 5/udp # Remote Job Entry
echo 7/tcp
echo 7/udp
discard 9/tcp sink null