• 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

    在这里插入图片描述

    在这里插入图片描述

    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
    iproute2net-toolsNote
    ip link showifconfig -a显示所有的外设
    ip link set down/up eth0ifconfig eth0 up/down启用/禁用网络接口
    ip addr add 192.168.0.10/24 dev eth0ifconfig eth0 192.168.0.10/24为网络接口分配IPv4地址
    ip addr del 192.168.0.10/24 dev eth0ifconfig eth0 0从网络接口删除IPv4地址
    ip addr show dev eth0ifconfig eth0显示网络接口的IPv4地址
    ip -6 addr add fe80::f0b7:57ff:fe2f:5f0d/64 dev eth1ifconfig eth1 inet6 add fe80::f0b7:57ff:fe2f:5f0d/64为网络接口分配IPv6地址
    ip -6 addr show dev eth0ifconfig eth0显示网络接口的IPv6地址
    ip link set dev eth0 address 02:42:20:d2:28:36ifconfig eth0 hw ether 02:42:20:d2:28:36更改网络接口的MAC地址
    ip route showroute -n显示IP路由表
    ip route add default via 192.168.0.1 dev eth0route add default gw 192.168.0.1 eth0添加默认的路由
    ip route replace default via 192.168.0.1 dev enp0s3route del default gw 192.168.0.1 enp0s3删除默认的路由
    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 enp0s3新增一个静态的路由
    ip route del 192.168.10.0/24route del -net 192.168.10.0/24删除静态的路由
    ssnetstat显示 socket – listening tcp/udp
    arp -anip neigh显示ARP表
    bridgebrctl管理网桥地址和设备
    用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
    
    • 1
    ip route s
    
    • 1
    ip route
    
    • 1
    ip rout
    
    • 1
    ip rou
    
    • 1
    ip ro
    
    • 1
    ip r
    
    • 1
    ip r s
    
    • 1
    ip r sh
    
    • 1
    ip r sho
    
    • 1
    ip r show
    
    • 1
    ip ro show
    
    • 1
    ip rou show
    
    • 1
    ip rout show
    
    • 1
    ip route show
    
    • 1

    例如:

    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
    
    • 1
    • 2
    • 3
    • 4

    第一行, default via 后面的就是网关, via是:经由,通过,路过的意思

    ip(8)
    ip-route - routing table management
    iproute2 (6.0.0-1)

    用 net-tools查看网关地址 : route -n
    route -n
    
    • 1

    例如

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
  • 相关阅读:
    智慧铁路:机车整备场数字孪生
    nginx+keepalived集群搭建
    IDEA如何将本地项目推送到GitHub上?
    【手写数据库toadb】SQL解析器的实现架构,create table/insert 多values语句的解析树生成流程和输出结构分析
    回溯算法总结
    puppeteer常规操作代码段
    Pico Neo3使用Unity开发简明教程
    SQL语句优化、mysql不走索引的原因、数据库索引的设计原则
    VS Code 调试Js代码,无法命中断点
    算法-乘积尾零
  • 原文地址:https://blog.csdn.net/kfepiza/article/details/127667772