[フレーム]
Last Updated: January 15, 2018
·
159.6K
· dmcrodrigues

Default gateway on CentOS

Routing

On CentOS you can check the routing table with:

$ route -n

The previous command prints a table like this:

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.254.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.185.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
0.0.0.0 192.168.185.2 0.0.0.0 UG 0 0 0 eth1

The last line of the table indicates the default gateway of the machine. In this case:

0.0.0.0 192.168.185.2 0.0.0.0 UG 0 0 0 eth1

Change default gateway

You can control default gateway using route command:

$ route del default gw <default_gateway_ip>
$ route add default gw <default_gateway_ip>

Keep in mind that this changes are only temporary. To change default gateway permanently you need to edit the file /etc/sysconfig/network and change to:

GATEWAY=<new_default_gateway_ip>

With multiple interfaces on the same subnet it's also possible designate the prefered route to the default gateway with:

GATEWAYDEV=<network_interface>

1 Response
Add your response

THANK YOU A LOT OF AFTER hard seach in the web and thousand responses here I found the right answer
it works with me perfect ......

over 1 year ago ·

AltStyle によって変換されたページ (->オリジナル) /