linux配置路由器命令,Linux下通过命令配置路由(英文)

7bff4ae0a01ac86cee1b79d9a1c1a43e.gifc1ef50e5a3b82d3b5e078434f76df342.gif

If static routes are required, they can be added to the routing table by means of the ip route add command and removed using the ip route del command. The more frequently used ip route commands take the following form:ip route [ add | del | change | append | replace ] destination-address

See the ip-route(8) man page for more details on the options and formats.

Use the ip route command without options to display the IP routing table. For example:~]$ ip route

default via 192.168.122.1 dev eth0 proto static metric 1024

192.168.122.0/24 dev ens9 proto kernel scope link src 192.168.122.107

192.168.122.0/24 dev eth0 proto kernel scope link src 192.168.122.126

To add a static route to a host address, in other words to a single IP address, issue a command as root:~]# ip route add 192.0.2.1 via 10.0.0.1 [dev ifname]

Where 192.0.2.1 is the IP address of the host in dotted decimal notation, 10.0.0.1 is the next hop address and ifname is the exit interface leading to the next hop.

To add a static route to a network, in other words to an IP address representing a range of IP addresses, issue the following command as root:~]# ip route add 192.0.2.0/24 via 10.0.0.1 [dev ifname]

where 192.0.2.0 is the IP address of the destination network in dotted decimal notation and /24 is the network prefix. The network prefix is the number of enabled bits in the subnet mask. This format of network address slash network prefix length is sometimes referred to as classless inter-domain routing (CIDR) notation.

Static route configuration can be stored per-interface in a /etc/sysconfig/network-scripts/route-interface file. For example, static routes for the eth0 interface would be stored in the /etc/sysconfig/network-scripts/route-eth0 file. The route-interface file has two formats: ip command arguments and network/netmask directives. These are described below.

See the ip-route(8) man page for more information on the ip route command.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值