Linux setup default gateway with route command
Q. How do I setup default gateway with a route command?
A. route command show and/or manipulate the IP routing table under Linux and UNIX oses.
Route manipulates the kernel's IP routing tables. Its primary use is to set up static routes to specific hosts or networks via an interface after it has been configured with the ifconfig program. When the add or del options are used, route modifies the routing tables. Without these options, route displays the current contents of the routing tables.
Display default route
Following three-command display the current routing table:# route
Output:
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 default dsl-router 0.0.0.0 UG 0 0 0 ra0
$ /sbin/route
Output:
Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 191.255.255.0 * 255.255.255.0 U 0 0 0 eth0 169.254.0.0 * 255.255.0.0 U 0 0 0 eth0 default 191.255.255.1 0.0.0.0 UG 0 0 0 eth0
You can use -n option, to display numerical addresses instead of trying to determine symbolic host names (via dns or /etc/hosts file). This is useful if you are trying to determine why the route to your nameserver has vanished.$ /sbin/route -n
Output:
Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 191.255.255.0 0.0.0.0 255.255.255.0 U 0 0 0 venet0 169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 venet0 0.0.0.0 191.255.255.1 0.0.0.0 UG 0 0 0 venet0
Please note that a destionation entry 0.0.0.0 (or default) is the default gatway. In above example 191.255.255.1 is a default gatway.
Add / setup a new route
The syntax is as follows:
route add default gw {IP-ADDRESS} {INTERFACE-NAME}
Where,
- IP-ADDRESS: Specify router IP address
- INTERFACE-NAME: Specify interface name such as eth0
For example if your router IP address is 192.168.1.254 type the following command as the root user:# route add default gw 192.168.1.254 eth0
OR use hostname such as dsl-router:# route add default gw dsl-router eth0
Setting route using GUI tools/command under Linux
If you find above command hard to use, consider using GUI tools. If your are using Red Hat/CentOS/Fedora core Linux type following command:# redhat-config-network
OR If you are using other Linux distribution use command:# network-admin
출처 : http://www.cyberciti.biz/faq/linux-setup-default-gateway-with-route-command/
'Skills > Unix, Linux' 카테고리의 다른 글
[강추]리눅스 스태틱 라우팅 설정 (0) | 2014.07.03 |
---|---|
telnet, ftp 설치 및 설정하기 (0) | 2014.06.26 |
우분투 터미널에서 다른 시스템에 ssh접속하기 (0) | 2014.06.16 |
다양한 OpenSource 가 존재 (0) | 2014.05.22 |
Programming with pcap (0) | 2014.05.22 |
댓글