跳转至

ip 命令


2013-10-29 by dongnan

举个栗子

查看路由:

ip route show
default via 192.168.168.1 dev em2 proto static metric 100 
192.168.168.0/24 dev em2 proto kernel scope link src 192.168.168.254 metric 100

添加路由:

ip route add 10.0.0.1 dev tun0
ip route add 10.0.1.0/24 dev tun0
ip route add 10.0.2.0/24 via 192.168.200.126

默认路由:

ip route add default via 10.0.2.254

删除路由:

ip route del 10.0.2.0/24 dev em2

命令帮助

man ip route

NAME
       ip-route - routing table management

SYNOPSIS
       ip [ ip-OPTIONS ] route  { COMMAND | help }

       ip route { show | flush } SELECTOR

       ip route { add | del | change | append | replace } ROUTE

DESCRIPTION
       ip route is used to manipulate entries in the kernel routing tables.

       Route types:
           unicast - the route entry describes real paths to the destinations covered by the route prefix.

           unreachable - these destinations are unreachable. Packets are discarded and the ICMP message host unreachable is generated.  The local senders get an EHOSTUNREACH error.

           blackhole - these destinations are unreachable. Packets are discarded silently.  The local senders get an EINVAL error.

           prohibit - these destinations are unreachable. Packets are discarded and the ICMP message communication administratively prohibited is generated. The local senders get an EACCES error.

           local - the destinations are assigned to this host. The packets are looped back and delivered locally.

           broadcast - the destinations are broadcast addresses. The packets are sent as link broadcasts.

           throw - a special control route used together with policy rules. If such a route is selected, lookup in this table is terminated pretending that no route was found. Without policy routing it
           is equivalent to the absence of the route in the routing table. The packets are dropped and the ICMP message net unreachable is generated. The local senders get an ENETUNREACH error.

           nat - a special NAT route. Destinations covered by the prefix are considered to be dummy (or external) addresses which require translation to real (or internal) ones before forwarding. The
           addresses to translate to are selected with the attribute via.  Warning: Route NAT is no longer supported in Linux 2.6.

           anycast - not implemented the destinations are anycast addresses assigned to this host. They are mainly equivalent to local with one difference: such addresses are invalid when used as the
           source address of any packet.

           multicast - a special type used for multicast routing. It is not present in normal routing tables.

参考

试试Linux下的ip命令,ifconfig已经过时了

回到页面顶部