linux目前都支持ip命令,与ifconfig类似,但ifconfig的软件net-tools早不更新了,ip功能更强大,推荐使用iproute2套件。
ip可以完美替换常用的网络命令,用法如下:
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
ip [ -force ] -batch filename
where OBJECT := { link | address | addrlabel | route | rule | neighbor | ntable |
tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm |
netns | l2tp | fou | tcp_metrics | token | netconf }
OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |
-h[uman-readable] | -iec |
-f[amily] { inet | inet6 | ipx | dnet | mpls | bridge | link } |
-4 | -6 | -I | -D | -B | -0 |
-l[oops] { maximum-addr-flush-attempts } | -br[ief] |
-o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |
-rc[vbuf] [size] | -n[etns] name | -a[ll] |?-c[olor]}
常用命令如下:
ip link
ip addr show eth0
ip addr add 192.168.0.100/24 dev eth0
ip addr del 192.168.0.100/24 dev eth0
ip route show
ip route get 10.42.0.47 ;获取ip地址的路由包从哪里来
ip route add default via 192.168.0.100
ip neighbour ;显示ARP MAC地址
ip link set ppp0 down ;断开连接,相当于ifconfig ppp0 down
ip link set ppp0 up ;连接,相当于ifconfig ppp0 up
ip route help
注意IP地址要有一个后缀,比如/24。这种用法用于在无类域内路由选择(CIDR)中来显示所用的子网掩码。
参考: