Hi, Gateway is essential in setting up network in a Unix as well as Windows based machine. This gateway can be added/removed as per our wish and current network conditions. Here I am listing some useful commands to set up gateway IP.
Add Route
========
# route add default gw GATEWAY_IP eth0
Delete Route
==========
# route del default gw GATEWAY_IP
Check Routing Table
===============
# route -n
Or
# netstat -r -n
Sample Output :
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.2.1 0.0.0.0 UG 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
Destination -- Destination host/network.
Gateway -- Gateway address.
Genmask -- Netmask for the destination net.
Flags :
U - route is up
H - target is a host
G -use gateway
You can also use the "ip" command to do the same.
View / Display Routing Table
------------------------------
# ip route show
In the output, You will have a bunch of entries and each entry is nothing but an entry in the routing table (Linux kernel routing table). For example, All network packets to a system in the same network are sent directly through the device eth0:
192.168.1.0/24 dev eth0 proto kernel scope link src IP_Address
Set a default route
--------------------
#ip route add default via gateway_ip
Delete route from table
------------------------
#ip route delete 192.168.1.0/24 dev eth0
Thats it