简介
iproute2是linux下管理控制TCP/IP网络和流量控制的新一代工具包,旨在替代老派的工具链net-tools,即大家比较熟悉的ifconfig,arp,route,netstat等命令。
net-tools是通过procfs(/proc)和ioctl系统调用去访问和改变内核网络配置,而iproute2则通过netlink套接字接口与内核通讯。
对照表
| net-tools | iproute2 |
|---|---|
| arp -na | ip neigh |
| ifconfig | ip link |
| ifconfig -a | ip addr show |
| ifconfig -s | ip -s link |
| ifconfig eth0 up | ip link set eth0 up |
| ipmaddr | ip maddr |
| iptunnel | ip tunnel |
| netstat | ss |
| netstat -i | ip -s link |
| netstat -g | ip maddr |
| netstat -l | ss -l |
| netstat -r | ip route |
| route add | ip route add |
| route del | ip route del |
| route -n | ip route show |
ss常用操作
-s查看当前服务器的网络连接统计
1 | ss -s |
-l查看所有监听的网络端口,-p并列出具体的程序名称
1 | ss -lp |
-a查看这台服务器上所有的socket连接
1 | ss -a |
替代netstat -ntlp
1 | ss -nltp|column -t |
替代lsof -i
1 | ss -nltp|grep 18010 |
ip常用操作
检查网卡的诸如 IP 地址
1 | ip addr show |
启用/禁用网卡
1 | ip link set eth0 up |
配置IP地址
1 | ip addr add 10.211.55.13/24 brd + dev eth0 |
检查路由
1 | ip route show |
检查ARP记录
1 | ip neigh |