整理自:https://www.cyberciti.biz/faq/linux-setup-default-gateway-with-route-command/
1. 查看默认Route
# route
或者
$ /sbin/route
同时可以使用-n选项来强制以数字形式的ip地址(而不是字母形式的主机名)来查看Route信息。
$ /sbin/route -n
2. 添加一个新的路由
形式如下:
route add default gw {IP-ADDRESS} {INTERFACE-NAME}
例如:
route add default gw 10.0.1.1 h2-eth0
上面这个例子是我在mininet中实际用的一条,要注意的是上面这条是在h2主机上设置的,也就是说后面的这个interface name指的是当前主机的interface名称,也就是从那个主机infertface发出的,而不是到达哪个interface(声明这么多是因为我被坑了好久TT)。
另外,Mininet中因为辨识方便所以接口都是形如 hX-ethX 这种形式。实际中接口大多就是简单的 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
以上两种是使用默认网关,同时我们也可以使用以下方式来指定到达某一网络的数据都从哪里走。
# ip route add 192.168.1.0/24 dev eth0
或者
# ip route add 192.168.1.0/24 via 192.168.1.254
最后,可以使用GUI来配置(这部分纯属转载,我并没有使用过)
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
浙公网安备 33010602011771号