net-tools 和 iproute2 笔记221103

181 阅读2分钟

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

在这里插入图片描述

在这里插入图片描述

iproute2net-toolsNote
ip link showifconfig -aDisplay all interfaces
ip link set down/up eth0ifconfig eth0 up/downEnable (UP)/Disable (DOWN) Network Interface
ip addr add 192.168.0.10/24 dev eth0ifconfig eth0 192.168.0.10/24Assign an IPv4 address to Network Interface
ip addr del 192.168.0.10/24 dev eth0ifconfig eth0 0Delete an IPv4 address from Network Interface
ip addr show dev eth0ifconfig eth0Display IPv4 address of a Network Interface
ip -6 addr add fe80::f0b7:57ff:fe2f:5f0d/64 dev eth1ifconfig eth1 inet6 add fe80::f0b7:57ff:fe2f:5f0d/64Assign an IPv6 address to a Network Interface
ip -6 addr show dev eth0ifconfig eth0Display IPv6 address of a Network Interface
ip link set dev eth0 address 02:42:20:d2:28:36ifconfig eth0 hw ether 02:42:20:d2:28:36Change the MAC Address of a Network Interface
ip route showroute -nShow IP Routing Table
ip route add default via 192.168.0.1 dev eth0route add default gw 192.168.0.1 eth0Add a Default Route
ip route replace default via 192.168.0.1 dev enp0s3route del default gw 192.168.0.1 enp0s3Delete a Default Route
ip route add 10.24.32.0/24 via 192.168.0.1 dev enp0s3route add -net 10.24.32.0/24 gw 192.168.0.1 dev enp0s3Add a Static Route
ip route del 192.168.10.0/24route del -net 192.168.10.0/24Delete a Static Route
ssnetstatDisplay socket - listening tcp/udp
arp -an ip neighDisplay ARP Table
bridgebrctlManage 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