This section introduces changing the IP address on an interface, changing the default gateway, and adding and removing a static route. With the knowledge of ifconfig and route output it's a small step to learn how to change IP configuration with these same tools.
For a practical example, let's say that the branch office server,
morgan, needs to visit the main office for some hardware maintenance.
Since the services on the machine are not in use, it's a convenient
time to fetch some software updates, after configuring the machine to
join the LAN.
Once the machine is booted and connected to the Ethernet, it's ready for IP reconfiguration. In order to join an IP network, the following information is required. Refer to the network map and appendix to gather the required information below.
Example 1.5. ifconfig and route output before the change
The process of readdressing for the new network involves three steps.
It is clear in
Example 1.5, “ifconfig and route
output before the change”, that
morgan is configured
for a different network than the main office desktop network.
active interface must be
brought down, then a
new address must be configured
on the interface and brought up, and finally
a new default route must be
added. If the networking configuration is correct and the
process is successful, the machine should be able to connect to local
and non-local destinations.
This is a fast way to stop networking on a single-homed machine such as a server or workstation. On multi-homed hosts, other interfaces on the machine would be unaffected by this command. This method of bringing down an interface has some serious side effects, which should be understood. Here is a summary of the side effects of bringing down an interface.
Side effects of bringing down an interface with ifconfig
all IP addresses on the specified interface are deactivated and removed
any connections established to or from IPs on the specified interface are broken 
all routes to any destinations through the specified interface are removed from the routing tables
the link layer device is deactivated
The next step, bringing up the interface, requires the new networking configuration information. It's a good habit to check the interface after configuration to verify settings.
Example 1.7. Bringing up an Ethernet interface with ifconfig
The second call to ifconfig allows verification of the IP addressing information. The currently configured IP address on eth0 is 192.168.99.14. Bringing up an interface also has a small set of side effects.
Side effects of bringing up an interface
the link layer device is activated
the requested IP address is assigned to the specified interface
all local, network, and broadcast routes implied by the IP configuration are added to the routing tables
Use ping to verify the reachability of other locally connected hosts or skip directly to setting the default gateway.
It should come as no surprise to a close reader
that the default route was removed at the execution of
ifconfig eth0 down. The crucial final step is
configuring the default route.
Example 1.8. Adding a default route with route
The routing table on
morgan should look exactly like the initial
routing table on
tristan. Compare the routing tables in
Example 1.1, “Sample ifconfig output” and
Example 1.8, “Adding a default route with route”.
These changes to the routing table on
morgan will stay in effect
until they are manually changed, the network is restarted, or the
machine reboots. With knowledge of the addressing scheme of a
network, and the use of
simple to readdress a machine on just about any Ethernet you can
attach to. The benefits of familiarity with these commands extend to
non-Ethernet IP networks as well, because these commands operate on the
IP layer, independent of the link layer.
morgan has joined the LAN at the main office and can
reach the Internet, a static route to the branch office would be
convenient for accessing resources on that network.
A static route is any route entered into a routing table which specifies at least a destination address and a gateway or device. Static routes are special instructions regarding the path a packet should take to reach a destination and are usually used to specify reachability of a destination through a router other than the default gateway.
As we saw above, in Section 1.2.3, “Static Routes to Networks”, a static route provides a specific route to a known destination. There are several pieces of information we need to know in order to be able to add a static route.
the address of the destination (192.168.98.0)
the netmask of the destination (255.255.255.0)
EITHER the IP address of the router through which the destination (192.168.99.1) is reachable
OR the name of the link layer device to which the destination is directly connected
Example 1.9. Adding a static route with route
Example 1.9, “Adding a static route with route” shows how to add a static route to the 192.168.98.0/24 network. In order to test the reachability of the remote network, ping any machine on the 192.168.98.0/24 network. Routers are usually a good choice, since they rarely have packet filters and are usually alive.
Because a more specific route is always chosen over a less specific route, it is even possible to support host routes. These are routes for destinations which are single IP addresses. This can be accomplished with a manually added static route as below.
Example 1.10. Removing a static network route and adding a static host route
This should serve as an illustration that there is no difference to the kernel in selecting a route between a host route and a network route with a host netmask. If this is a surprise or is at all confusing, review the use of netmasks in IP networking. Some collected links on general IP networking are available in Section I.1.3, “General IP Networking Resources”.
 The network address can be calculated from the IP address and netmask. Refer to Section H.1, “ipcalc and other IP addressing calculators”. Especially handy is the variable length subnet mask RFC, RFC 1878.
 Many networks are configured with the name resolution services on a publicly connected host. See Section 12.6, “DNS Troubleshooting”.
 It is possible for a linux box which meets the following three criteria to maintain connections and provide services without having the service IP configured on an interface. It must be functioning as a router, be configured to support non-local binding and be in the route path of the client machine. This is an uncommon need, frequently accomplished by the use of transparent proxying software.