satu

Gajah mati meninggalkan tulang
harimau mati meninggalkan belang
manusia mati meninggalkan nama

persiapkan klu kalian mati ingin meninggalkan apa ?

Tuesday, 4 September 2018

command routing linux add / delete

sumber : http://www.softpanorama.org/Net/Netutils/route_in_linux.shtml




  • ... ... ...
    B. Check for kernel compatibility (I think this is irrelevant. Also SLES 11 has different options. In both cases all the necessary options are enabled in stock kernel --NNB):
    i. cd /usr/src/linux
    ii. make menuconfig
    iii. Follow: Networking -> Networking Options -> And make sure the following are selected:
    • TCP/IP Networking
    • IP: advanced router
    • IP: Policy Routing
    • IP: use netfilter MARK value as routing key
    • IP: Choose IP: FIB lookup algorithm (FIB_HASH)
    2. Create a new policy routing table for each interface:
    echo "1 corporate">> /etc/iproute2/rt_tables
    3. Provide IP info / gateway to the new corporate table.
    ip route add 192.168.0.0/24 dev eth0 src 192.168.0.99 table corporate
    ip route add default via 192.168.0.1 dev eth0 table corporate
    4. Create IP rules to handle inbound / outbound traffic on this network.
    ip rule add from 192.168.0.99/32 table corporate
    ip rule add to 192.168.0.99/32 table corporate 

Typical Operations

To check the content of the routing table in Linux (see netstat):

netstat -r # with DNS names
netstat -rn # with IP addresses

Adding and Removing a Network in Linux

route add -net 10.10.10.0/24 gw 192.168.0.1
route del -net 10.10.10.0/24 gw 192.168.0.1

Adding and Removing a specific host is Linux-flavor specific:

route add -host 10.10.10.45 gw 192.168.0.1
route del -host 10.10.10.45 gw 192.168.0.1
You can also specify netmask and interface
route del -net 10.1.0.0 netmask 255.255.0.0 gw 10.2.0.1 eth0 
route del -host 10.10.0.5 netmask 255.255.0.0 gw 10.2.0.1 eth0 

Adding a Default GW in Linux

route add default gw 192.168.0.1
route del default gw 192.168.0.1
You can also specify it in /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=box17
GATEWAY=10.194.176.1

Flashing routing table

ip route flush
Note:
  • You can also use ip command to manipulate routes in Linux.
  • Routes added using route command exists until reboot. For Solaris you can add them permanently using option -p of the route command. In this case these routes are stored in /etc/inet/static_routes. Linux has no such capability.

Making routing entries permanent

In Solaris and other Unixes to make routing entry permanent you need to use -p option of the route command. That's it. Linux guys decided to reinvent the bicycle and that shows.
In Suse to make routing entries permanent you need to put them into a special table of static routes that will be read on boot. It is stored in /etc/sysconfig/network/route file. The file has the format of output of the route -rn command, so it's a pretty elegant approach. But only if you know about it ;-). See Suse static routes table for more details.
In Red Hat, Fedora, Centos, and Oracle Linux this issue is an over-engineered mess. There is no system wide table to store static route information. It is stored on interface basis. For each interface you need to define and maintain/etc/sysconfig/network-scripts/route-eth<number> (or other network interface) file. Such interface config file exists for each valid network interface card.  For example, static routes for the eth0 interface would be stored in the /etc/sysconfig/network-scripts/route-eth0 file.
There are two formats acceptable in this file
  • New and bad
  • Old and horrible
We will start with the new format as it causes less allergy. It is available since Red Hat 8, I think. In this case the route-interface file has two types of directives: one for default router and the other for network/netmask directives. Here is an example from Centos deployment guide:
The following is a sample route-eth0 file using the IP command arguments format. The default gateway is 192.168.0.1, interface eth0. The two static routes are for the 10.10.10.0/24 and 172.16.1.0/24 networks:
default 192.168.0.1 dev eth0
10.10.10.0/24 via 192.168.0.1 dev eth0
172.16.1.0/24 via 192.168.0.1 dev eth0
There is also older, pretty stupid format that for compatibility is still accepted. You should never use it, but it might be useful to be aware about its existence:
You can also use the network/netmask directives format for route-interface files. The following is a template for the network/netmask format, with instructions following afterwards:
ADDRESS0=X.X.X.X
NETMASK0=X.X.X.X
GATEWAY0=X.X.X.X
Where:
  • ADDRESS0=X.X.X.X is the network number for the static route.
  • NETMASK0=X.X.X.X is the netmask for the network number defined with ADDRESS0=X.X.X.X.
  • GATEWAY0=X.X.X.X is the default gateway, or an IP address that can be used to reach ADDRESS0=X.X.X.X
The following is a sample route-eth0 file using the network/netmask directives format. The default gateway is 192.168.0.1, interface eth0. The two static routes are for the 10.10.10.0/24 and 172.16.1.0/24 networks. However, as mentioned before, this example is not necessary as the 10.10.10.0/24 and 172.16.1.0/24 networks would use the default gateway anyway:
ADDRESS0=10.10.10.0
NETMASK0=255.255.255.0
GATEWAY0=192.168.0.1
ADDRESS1=172.16.1.0
NETMASK1=255.255.255.0
GATEWAY1=192.168.0.1
Subsequent static routes must be numbered sequentially, and must not skip any values. For example, ADDRESS0ADDRESS1ADDRESS2, and so on. --[That make deletion a labor intensive operation --NNB;-)]
Below is an example of setting static routes to a different subnet, on a machine in the 192.168.0.0/24 subnet. The example machine has an eth0 interface in the 192.168.0.0/24 subnet, and an eth1 interface (10.10.10.1) in the 10.10.10.0/24 subnet:
ADDRESS0=10.10.10.0
NETMASK0=255.255.255.0
GATEWAY0=10.10.10.1
What's really funny is that this horrible way of specifying static routes was essentially a change from Suse-style that was used in Red Hat 7 (after all Suse is a Red Hat derivative). Yes, Red Hat 7 used to have a "normal" way to define static routes using /etc/sysconfig/static-routes table (Static Routes in Red Hat 8.0):
As of Red Hat 8.0, Red Hat has changed the way in which non-default static routes are initialized and added to the routing table on startup. Since this process is not documented, I've made a few notes here.Traditionally, static routes were added in /etc/sysconfig/static-routes, in the form:
iface type dest-addr netmask netmask gw gateway-addr 
 ... 
such as this example, taken from a real system:
eth0 net 192.168.170.0 netmask 255.255.255.0 gw 192.168.168.1

This would cause the startup scripts to execute a command like this
route add -type dest-addr netmask netmask gw gateway-addr ... iface
Notice the ellipsis at the end of the line there - this means that other options for the route add command can be specified in static-routes, which is particularly useful for specifying metrics - something that is quite common in moderately complex intranets. Other options, such as maximum segment size, initial window size and initial round-trip time, may also be useful.
In Red Hat 8.0, attempts to add interface-specific routes in static-routes will fail. Instead, static routes must be specified as multiple variables in multiple files in /etc/sysconfig/networking/devices. For example, a static route for the eth0 device must be specified in a file called eth0.route, like this:
ADDRESS0=192.168.170.0
NETMASK0=255.255.255.0
GATEWAY0=192.168.168.1

No comments:

Post a Comment