Monday, December 19, 2016

Configuring Network IV

Configuring Routing Parameters




You may have noticed that we didn’t configure two important IP
parameters in the preceding topics in this chapter: the default
gateway router address and the DNS server address.



Using the IP protocol, routers do just what their name implies: they
route data across multiple networks to deliver information to a
destination host. Routers operate at the Network layer and are used to
connect various networks together.




Routers are usually implemented in conjunction with a gateway. The
router hardware itself may be as simple as a computer system with two
NICs installed, or it may be a specialized hardware appliance
dedicated to routing.




One of the key jobs performed by routers is to determine the best way
to get information to the right destination host. To do this, a router
maintains a routing table of available routes. Routers use an
algorithm that evaluates distance, cost, and network status to
determine the best route to the destination host. Even if it isn’t
configured as a router, every Linux system maintains a routing table
in RAM that it uses to determine where to send data on a network.




When you’re configuring networking parameters on a Linux system, one
of the key tasks you need to perform is to configure the default
router address. The default router is the default location packets
are sent to if they are addressed to a host that doesn’t reside on the
local network segment.


Your default gateway router address is stored in the 



/etc/sysconfig/network/routes 



file, shown here:




openSUSE:/ # cat /etc/sysconfig/network/routes
default 10.0.0.1 - ens32




The syntax for specifying the default route in this file is


default router_IP_address



Notice in the preceding example that the default gateway router address is set to 10.0.0.1.




TIP  If you have more than one NIC installed and each interface needs
its own routing configuration (for example, if each NIC is connected
to a different network), you can define an additional routing
configuration file in 


/etc/sysconfig/network/ 



named



ifroute-interface_name





The syntax for adding a route to the routes file is shown next:




DESTINATION       GATEWAY          NETMASK   INTERFACE     [TYPE]





DESTINATION

The first column contains the route’s destination. It may contain the
IP address or DNS hostname of a network or host. Entering default in
this column indicates the route is the default route.


NOTE  I recommend you use IP addresses, not DNS names, in this file. If
your DNS server were to go down or become unreachable, routing would
be gone!



GATEWAY

The second column contains the IP address of the router through which
the specified host or a network can be reached. In this column,
specify the IP address of a router that can route the information to
the remote network or host.




NETMASK

The third column contains the netmask for the network or host behind
the router. The fourth column applies the route to a specific
interface. If nothing is specified, the route applies to all
interfaces.


NOTE If you want to leave a column in this file blank, be sure to
enter a dash (-).




[TYPE]

The fifth column is optional. It is used to specify the route type.
You can enter one of the following:


   • unicast The route specifies a real path to the destination route.

   • local The destination is the localhost. Packets sent to this route
     are looped back and delivered to the local machine.

   • broadcast The destination is a broadcast address. Packets sent to
     this route are sent as link broadcasts.

   • multicast Used for multicast routing. This type of route is not
     typically used with most routing tables.

  • unreachable Configures the route destination as unreachable. Packets
    sent to this route are silently dropped.




Here is a sample entry in a routes file:



207.68.156.51     207.68.145.45     255.255.255.0    ens32



After making any changes to the routes file, you will need to restart
your network interface by entering


ifdown interface


followed by


ifup interface




For your LPIC-1/CompTIA Linux+ exam, you also need to be familiar with
how to manage routes with the route command at the shell prompt. You
use the route command to display or modify the routing table on the
Linux host. If you enter


route 


without options, it simply displays the current routing table, as shown in this example:




 openSUSE:/ # route
Kernel IP routing table
Destination    Gateway     Genmask           Flags Metric Ref   Use Iface
default        10.0.0.1    0.0.0.0           UG    0      0     0 ens32
10.0.0.0       *           255.255.255.0     U     0      0     0 ens32
loopback       *           255.0.0.0         U     0      0     0 lo



You can add routes to the host’s route table by entering



route add –net network_address netmask netmask gw router_address



For example, suppose you need to add a route to the 192.168.2.0/24 network through
the router with an IP address of 10.0.0.254. You could do this by
entering



route add –net 192.168.2.0 netmask 255.255.255.0 gw 10.0.0.254 



at the shell prompt.



You can also remove existing routes from the routing table on a Linux
host using the route command. This is done by entering



route del –net network_address netmask netmask gw router_address 



at the shell prompt.


For example, suppose you want to remove the route just added in the
preceding paragraph. You could do this by entering



route del –net 192.168.2.0 netmask 255.255.255.0 gw 10.0.0.254 



at the shell prompt.



You can also use route to set the default route. This is done by
entering



route add default gw router_address 



at the shell prompt. For example, if you want to add 10.0.0.254 as your default gateway router,
you would enter




route add default gw 10.0.0.254 



at the shell prompt.




TIP    Changes made with the route command are not persistent! If you
want the route changes to be persistent across reboots, you need to
add them to your



/etc/sysconfig/network/routes 



file.



You can also use the ip command at the shell prompt to manage routing.
For example, to view the routing table, you can enter ip route show at
the shell prompt, as shown here:


openSUSE:/ # ip route show
default via 10.0.0.1 dev ens32
10.0.0.0/24 dev ens32  proto kernel  scope link  src 10.0.0.83
127.0.0.0/8 dev lo  scope link




You can also use the ip command to add a static route to the routing
table. This is done by entering



ip route add network/prefix via router_ip_address dev interface 



at the shell prompt. In the following example shown, I’ve added a route to the
192.168.5.0/24 network through a router with an IP address of 10.0.0.254:





openSUSE:/ # ip route add 192.168.5.0/24 via 10.0.0.254 dev ens32
openSUSE:/ # ip route show
default via 10.0.0.1 dev ens32
10.0.0.0/24 dev ens32  proto kernel  scope link  src 10.0.0.83
127.0.0.0/8 dev lo  scope link
192.168.5.0/24 via 10.0.0.254 dev ens32





You can also remove a route from the routing table by entering



ip route del network/prefix 



at the shell prompt.


For example, to remove the 192.168.5.0/24 route I just added, I would enter



ip route del 192.168.5.0/24








LX0-104 Exam Objectives (S)









No comments:

Post a Comment