How to set default gateway in Linux.

How to set default gateway in linux | It’s very important to setup default gateway in linux/solaris/unix server to access the server from client machine. You can configure the static or temporary routing.

Setup default gateway in linux.

Before going to add default gateway in your operating system, delete your existing default gateway if you intend to change it.

#route del default gw

How to set default gateway in linux

syntax to add default gateway:-

route add default gw {IP_Address} {Interface_name}

Here adding correct default gateway using route add command.

route add default gw eth0

Add default gateway in new or old linux server.

#ip route add default via dev eth0

Static route configuration can be done in /etc/sysconfig/network-scripts/route-interface file.

for example, static routes for the eth0 interface can be done as below.

#cat /etc/sysconfig/network-scripts/route-eth0

Later we can check the routing status.

#route -n or netstat -nr

Useful Posts:-

How to add route in Linux in best way

Leave a Comment