≡ Menu

default gateway

Linux route Add Command Examples

I am a new Linux user. How do I add a new or default gateway using route command on Linux operating systems? How can I use route command to show or set a new route on Linux based server or desktop system?
[click to continue…]

Red Hat / CentOS Linux Setting a Default Gateway

Q. How do I setup up a default Gateway for all interfaces (eth0 and eth1) under CentOS Linux 5?

A.There are different ways to setup TCP/IP hosts so that you can reach to remote destinations. The simplest one is to setup default gateway by modifying the /etc/sysconfig/network

Setup a default Gateway

Open /etc/sysconfig/network file:
# vi /etc/sysconfig/network
Setup GATEWAY={Router-IP}, if router IP is 74.86.49.129, type:
GATEWAY=74.86.49.129
Save and close the file. Here is my complete file:
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=wan.nixcraft.in
GATEWAY=74.86.49.129

You need to restart networking service:
# /etc/init.d/networking restart

Debian / Ubuntu Linux Setting a Default Gateway

Q. How do I setup a default gateway on Debian or Ubuntu Linux? My router IP is 192.168.1.254 and I'd like to setup this as a default gateway for Debian Linux.

A. You can use command line tool such as
a] ip command - show / manipulate routing, devices, policy routing and tunnels

b] route command - show / manipulate the IP routing table

c] Save routing information to a configuration file so that after reboot you get same default gateway.

ip command to set a default router to 192.168.1.254

Login as the root and type:
# ip route add default via 192.168.1.254
OR
$ sudo ip route add default via 192.168.1.254

route command to set a default router to 192.168.1.254

Login as the root and type:
# route add default gw 192.168.1.254
OR
$ sudo route add default gw 192.168.1.254

Save routing information to a configuration file /etc/network/interfaces

Open /etc/network/interfaces file
# vi /etc/network/interfaces
OR
$ sudo vi /etc/network/interfaces
Find eth0 or desired network interface and add following option
gateway 192.168.1.254
Save and close the file. Restart networking:
# /etc/init.d/networking restart
OR
$ sudo /etc/init.d/networking restart

Linux setup default gateway with route command

How do I setup default gateway with a route command on a Linux operating systems?
[click to continue…]