Linux networking cheat sheet

曾嘉荣
2023-12-01

路由

项目iproute2net-tools
查看套接字统计信息ssnetstat
查看套接字统计信息(show listening only)ss -lnetstat -l
监视网络接口ip monitor<NA>
查看网络接口统计信息ip -s linkifconfig -s
查看所有已连接的网络接口ip link showifconfig -a
启用网络接口ip link set eth1 upifconfig eth1 up
停用网络接口ip link set eth1 downifconfig eth1 down
改变网络接口的MAC地址ip link set dev eth1 address 08:00:27:75:2a:67ifconfig eth1 hw ether 08:00:27:75:2a:66
查看网络接口的IPv4地址ip addr show dev eth1ifconfig eth1
添加网络接口的IPv4地址ip addr add 10.0.0.1/24 dev eth1ifconfig eth1 10.0.0.1/24
删除网络接口的IPv4地址ip addr del 10.0.0.1/24 dev eth1ifconfig eth1 0
删除网络接口的所有IPv4地址ip addr flush dev eth1<NA>
查看网络接口的IPv6地址ip -6 addr show dev eth1ifconfig eth1
添加网络接口的IPv6地址ip -6 addr add 2002:0db5:0:f102::1/64 dev eth1ifconfig eth1 inet6 add 2002:0db5:0:f102::1/64
删除网络接口的IPv6地址ip -6 addr del 2002:0db5:0:f102::1/64 dev eth1ifconfig eth1 inet6 del 2002:0db5:0:f102::1/64
查看IPv4路由表ip route showroute -n
查看IPv4路由表ip route shownetstat -rn
添加IPv4默认路由ip route add default via 192.168.1.2 dev eth0route add default gw 192.168.1.2 eth0
删除IPv4默认路由ip route del default via 192.168.1.1 dev eth0route del default gw 192.168.1.1 eth0
修改IPv4默认路由ip route replace default via 192.168.1.2 dev eth0<NA>
添加IPv4静态路由ip route add 172.16.32.0/24 via 192.168.1.1 dev eth0route add -net 172.16.32.0/24 gw 192.168.1.1 dev eth0
删除IPv4静态路由ip route del 172.16.32.0/24route del -net 172.16.32.0/24
删除IPv4所有路由ip route flush dev eth0<NA>
查看IPv4路由出口ip -s route get 192.168.1.1<NA>
查看ARP表ip neigharp -an
添加静态ARP项ip neigh add 192.168.1.100 lladdr 00:0c:29:c0:5a:ef dev eth0arp -s 192.168.1.100 00:0c:29:c0:5a:ef
删除静态ARP项ip neigh del 192.168.1.100 dev eth0arp -d 192.168.1.100
查看多播地址ip maddr list dev eth0ipmaddr show dev eth0
添加多播地址ip maddr add 33:44:00:00:00:01 dev eth0ipmaddr add 33:44:00:00:00:01 dev eth0
删除多播地址ip maddr del 33:44:00:00:00:01 dev eth0ipmaddr del 33:44:00:00:00:01 dev eth0

ref:
iproute2 对决 net-tools


策略路由

项目iproute2
查看IPv4策略路由规则ip rule show
添加IPv4策略路由规则ip rule add from 192.168.0.0/24 to 192.168.1.0/24 iif eth0 oif eth1 fwmak 0x1234 table 1 pref 100
删除IPv4策略路由规则ip rule del from 192.168.0.0/24 to 192.168.1.0/24 iif eth0 oif eth1 fwmak 0x1234 table 1 pref 100
查看IPv4策略路由的路由表ip route show table 1
添加IPv4策略路由的默认路由ip route add table 1 default via 192.168.1.2 dev eth0
删除IPv4策略路由的默认路由ip route del table 1 default via 192.168.1.1 dev eth0
修改IPv4策略路由的默认路由ip route replace table 1 default via 192.168.1.2 dev eth0
添加IPv4策略路由静态路由ip route add table 1 172.16.32.0/24 via 192.168.1.1 dev eth0
删除IPv4策略路由静态路由ip route del table 1 172.16.32.0/24

项目描述
加载桥模块modprobe bridge
项目语法例子
add bridgebrctl addbr <bridge>
delete bridgebrctl delbr <bridge>
add interface to bridgebrctl addif <bridge> <device>
delete interface from bridgebrctl delif <bridge> <device>
turn hairpin on/offbrctl hairpin <bridge> <port> {on|off}
set ageing timebrctl setageing <bridge> <time>
set bridge prioritybrctl setbridgeprio<bridge> <prio>
set bridge forward delaybrctl setfd <bridge> <time>
set hello timebrctl sethello <bridge> <time>
set max message agebrctl setmaxage <bridge> <time>
set path costbrctl setpathcost <bridge> <port> <cost>
set port prioritybrctl setportprio <bridge> <port> <prio>
show a list of bridgesbrctl show [ <bridge> ]
show a list of mac addrsbrctl showmacs <bridge>
show bridge stp infobrctl showstp <bridge>
turn stp on/offbrctl stp <bridge> {on|off}

vlan

项目描述
加载vlan模块modporbe 8021q
项目iproute2net-tools
添加vlan网络接口ip link add link eth0 name eth0.5 type vlan id 5vconfig add eth0 5
删除vlan网络接口ip link delete eth0.5vconfig rem eth0.5

注意:
一个的物理网络接口,只有一个的vlan id。可以看作为 access 口。
一个的物理网络接口,如果有多于一个的vlan id。可以看作为 trunk 口。

 类似资料:

相关阅读

相关文章

相关问答