net-tools起源于BSD的TCP/IP工具箱,后来成为老版本Linux内核中配置网络功能的工具,但Linux社区自2001年起已对其停止维护。最新的Linux发行版,如Arch Linux、CentOS 7/8、RHEL 7及以后版本等已经完全抛弃net-tools,默认仅支持iproute2。
iproute2的出现旨在从功能上取代net-tools。
net-tools通过procfs(/proc)和ioctl系统调用去访问和改变内核网络配置,iproute2则通过netlink套接字接口与内核通讯。iproute2的用户接口比net-tools更加直观,如各种网络资源(如link、IP地址、路由和隧道等)均使用合适的对象抽象去定义,使得用户可使用一致的语法去管理不同的对象。
ifconfig、hostname、mii-tool、netstat、route
等,均属于net-tools
工具
iproute2
的命令都以ip
开头, 如ip address
, ip route
, ip link
等
iproute2 | net-tools | Note |
ip link show | ifconfig -a | Display all interfaces |
ip link set down/up eth0 | ifconfig eth0 up/down | Enable (UP)/Disable (DOWN) Network Interface |
ip addr add 192.168.0.10/24 dev eth0 | ifconfig eth0 192.168.0.10/24 | Assign an IPv4 address to Network Interface |
ip addr del 192.168.0.10/24 dev eth0 | ifconfig eth0 0 | Delete an IPv4 address from Network Interface |
ip addr show dev eth0 | ifconfig eth0 | Display IPv4 address of a Network Interface |
ip -6 addr add fe80::f0b7:57ff:fe2f:5f0d/64 dev eth1 | ifconfig eth1 inet6 add fe80::f0b7:57ff:fe2f:5f0d/64 | Assign an IPv6 address to a Network Interface |
ip -6 addr show dev eth0 | ifconfig eth0 | Display IPv6 address of a Network Interface |
ip link set dev eth0 address 02:42:20:d2:28:36 | ifconfig eth0 hw ether 02:42:20:d2:28:36 | Change the MAC Address of a Network Interface |
ip route show | route -n | Show IP Routing Table |
ip route add default via 192.168.0.1 dev eth0 | route add default gw 192.168.0.1 eth0 | Add a Default Route |
ip route replace default via 192.168.0.1 dev enp0s3 | route del default gw 192.168.0.1 enp0s3 | Delete a Default Route |
ip route add 10.24.32.0/24 via 192.168.0.1 dev enp0s3 | route add -net 10.24.32.0/24 gw 192.168.0.1 dev enp0s3 | Add a Static Route |
ip route del 192.168.10.0/24 | route del -net 192.168.10.0/24 | Delete a Static Route |
ss | netstat | Display socket - listening tcp/udp |
arp -an | ip neigh | Display ARP Table |
bridge | brctl | Manage bridge addresses and devices |
用iproute2查看网关地址
用 ip route show
可写为:
- ip route show
- ip route sho
- ip route sh
- ip route s
- ip route
- ip rout
- ip rou
- ip ro
- ip r
- ip r s
- ip r sh
- ip r sho
- ip r show
- ip ro show
- ip rou show
- ip rout show
- ip route show
ip route sh
ip route s
ip route
ip rout
ip rou
ip ro
ip r
ip r s
ip r sh
ip r sho
ip r show
ip ro show
ip rou show
ip rout show
ip route show
例如:
root@ds10:~# ip r
default via 10.82.10.12 dev ens33 onlink
10.0.0.0/8 dev ens33 proto kernel scope link src 10.10.12.25
169.254.0.0/16 dev ens33 scope link metric 1000
第一行, default via 后面的就是网关, via是:经由,通过,路过的意思
ip(8) ip-route - routing table management iproute2 (6.0.0-1)
用 net-tools查看网关地址 : route -n
route -n
例如
root@ds10:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.82.10.12 0.0.0.0 UG 0 0 0 ens33
10.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 ens33
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 ens33