Thursday, December 29, 2011

add a default route in Linux

Sometimes, even after cmd "dhclient eth0", the machine still cannot ping outside machines.

Then, I use cmd "route" to check the current route, and get sth like this:

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 * 255.255.255.0 U 0 0 0 ra0

So there is no default gatway. Next I use the following command to add a default route:

"route add default gw 192.168.2.1 eth0"
(The IP of the gateway could be the current IP address and change the last number to 1.)

Ref:
http://www.cyberciti.biz/faq/linux-setup-default-gateway-with-route-command/

No comments: