net-tools 和 iproute2 笔记221103

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

net-tools 和 iproute2 笔记221103_第1张图片

net-tools 和 iproute2 笔记221103_第2张图片

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 net-tools Note
ip link show ifconfig -a 显示所有的外设
ip link set down/up eth0 ifconfig eth0 up/down 启用/禁用网络接口
ip addr add 192.168.0.10/24 dev eth0 ifconfig eth0 192.168.0.10/24 为网络接口分配IPv4地址
ip addr del 192.168.0.10/24 dev eth0 ifconfig eth0 0 从网络接口删除IPv4地址
ip addr show dev eth0 ifconfig eth0 显示网络接口的IPv4地址
ip -6 addr add fe80::f0b7:57ff:fe2f:5f0d/64 dev eth1 ifconfig eth1 inet6 add fe80::f0b7:57ff:fe2f:5f0d/64 为网络接口分配IPv6地址
ip -6 addr show dev eth0 ifconfig eth0 显示网络接口的IPv6地址
ip link set dev eth0 address 02:42:20:d2:28:36 ifconfig eth0 hw ether 02:42:20:d2:28:36 更改网络接口的MAC地址
ip route show route -n 显示IP路由表
ip route add default via 192.168.0.1 dev eth0 route add default gw 192.168.0.1 eth0 添加默认的路由
ip route replace default via 192.168.0.1 dev enp0s3 route del default gw 192.168.0.1 enp0s3 删除默认的路由
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 新增一个静态的路由
ip route del 192.168.10.0/24 route del -net 192.168.10.0/24 删除静态的路由
ss netstat 显示 socket – listening tcp/udp
arp -an ip neigh 显示ARP表
bridge brctl 管理网桥地址和设备
用iproute2查看网关地址

ip route show

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

你可能感兴趣的:(学习笔记,解决问题,过程记录,#,Linux,CentOS,Ubuntu,等,#,控制台命令行,Shell脚本,sh,cmd,等,网络,linux,服务器,tcp/ip,command,pattern)