1、Switch
在mt7621 的用户手册上有switch的使用说明
root@FS1:~# switch dump 2> /dev/null | grep -v "hash"| grep -v "found" |grep -E "\-[1\-][1\-][1\-]----" > test
root@FS1:~# cat test
538: ---1---- 0 1 288 f48e38fa00f9 - -
604: ---1---- 0 1 292 000c29bd26f9 - -
上面的意思就是把port 123的记录下来,作为有线lan口的设备
2、brctl
root@CMCC:/proc/5560/net# brctl
Usage: brctl COMMAND [BRIDGE [INTERFACE]]
Manage ethernet bridges
Commands:
show Show a list of bridges
addbr BRIDGE Create BRIDGE
delbr BRIDGE Delete BRIDGE
showmacs BRIDGE Show fdb of BRIDGE
addif BRIDGE IFACE Add IFACE to BRIDGE
delif BRIDGE IFACE Delete IFACE from BRIDGE
setageing BRIDGE TIME Set ageing time
setfd BRIDGE TIME Set bridge forward delay
sethello BRIDGE TIME Set hello time
setmaxage BRIDGE TIME Set max message age
setpathcost BRIDGE COST Set path cost
setportprio BRIDGE PRIO Set port priority
setbridgeprio BRIDGE PRIO Set bridge priority
stp BRIDGE [1/yes/on|0/no/off] STP on/off
root@CMCC:/proc/5560/net# brctl show
bridge name bridge id STP enabled interfaces
br-lan 7fff.b20a32d69898 no eth0
eth1
ra0
ra1
ra2
ra3
rax0
rax1
rax2
rax3
root@FS1:~# brctl showmacs br-lan
protno interface sourcemac is_local?
1 eth0 F4:8E:38:FA:00:F9 no
1 eth0 AA:5C:61:9B:4C:CF yes
2 ra0 00:0C:43:26:46:F8 yes
6 rax0 02:0C:43:46:46:F8 yes
root@FS1:~# brctl showmacs br-lan |grep -vi yes
protno interface sourcemac is_local?
1 eth0 F4:8E:38:FA:00:F9 no
以mt7621为例操作:
root@FS1:~
apclix0 Link encap:Ethernet HWaddr 0A:0C:43:26:46:E0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
br-lan Link encap:Ethernet HWaddr 3A:47:1E:8D:96:58
inet addr:192.168.20.53 Bcast:192.168.20.255 Mask:255.255.255.0
inet6 addr: fe80::124/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8442959 errors:0 dropped:6608 overruns:0 frame:0
TX packets:10158 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:611515263 (583.1 MiB) TX bytes:3460648 (3.2 MiB)
br-lan:1 Link encap:Ethernet HWaddr 3A:47:1E:8D:96:58
inet addr:192.168.10.1 Bcast:192.168.10.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth0 Link encap:Ethernet HWaddr 3A:47:1E:8D:96:58
inet6 addr: fe80::3847:1eff:fe8d:9658/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8485218 errors:0 dropped:10081 overruns:0 frame:0
TX packets:18295 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:740235124 (705.9 MiB) TX bytes:5219554 (4.9 MiB)
Interrupt:10
eth1 Link encap:Ethernet HWaddr 4E:44:1B:86:3B:F2
inet6 addr: fe80::4c44:1bff:fe86:3bf2/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:8443281 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:764654315 (729.2 MiB)
Interrupt:10
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:200 errors:0 dropped:0 overruns:0 frame:0
TX packets:200 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:18094 (17.6 KiB) TX bytes:18094 (17.6 KiB)
ra0 Link encap:Ethernet HWaddr 00:0C:43:26:46:E0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:1570 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:31
rax0 Link encap:Ethernet HWaddr 02:0C:43:46:46:E0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:19649 errors:0 dropped:0 overruns:0 frame:0
TX packets:8025 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3528948 (3.3 MiB) TX bytes:7826739 (7.4 MiB)
关掉2.4Gwifi热点:
ifconfig ra0 down
brctl delif br-lan ra0
打开2.4Gwifi热点:
ifconfig ra0 up
brctl addif br-lan ra0
3、ip
怎样通过mac地址获取ip地址?
function lan_get_ip_via_mac() {
local mac=$1
local dhcp_path=/tmp/dhcp.leases
local ip_addr
ip_addr=$(ip -4 neigh 2> /dev/null | grep -vi STALE | grep -i ${mac} | sed -n 1p | awk -F ' ' '{print $1}' 2> /dev/null)
[ -n "${ip_addr}" ] && {
echo ${ip_addr}
}
}
ip -4 neigh show # 只返回设备的IPv4地址。IPv4邻居表也称为ARP表,可以用arp -a
ip -6 neigh show # 只返回设备的IPv6地址
3、netstat
如何获取网关ip?
root@FS1:~# netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
default 192.168.20.1 0.0.0.0 UG 0 0 0 eth1
192.168.10.0 * 255.255.255.0 U 0 0 0 br-lan
192.168.20.0 * 255.255.255.0 U 0 0 0 eth1
192.168.20.1 * 255.255.255.255 UH 0 0 0 eth1
root@FS1:~# netstat -r |grep default |cut -f 10 -d ' '
192.168.20.1
如何获取网关的mac地址?
root@FS1:~# cat /proc/net/arp
IP address HW type Flags HW address Mask Device
192.168.20.1 0x1 0x2 50:98:b8:83:e7:ce * eth1
192.168.10.2 0x1 0x2 f4:8e:38:fa:00:f9 * br-lan
root@FS1:~# cat /proc/net/arp |grep -w 192.168.20.1 |awk '{print $4}'
50:98:b8:83:e7:ce
linux netstat 命令用于显示网络状态。利用 netstat 指令可让你得知整个 Linux 系统的网络情况。
- -r或–route 显示Routing Table。
- -s或–statistics 显示网络工作信息统计表。
- -t或–tcp 显示TCP传输协议的连线状况。
- -u或–udp 显示UDP传输协议的连线状况。
- -C或–cache 显示路由器配置的快取信息。
- -e或–extend 显示网络其他相关信息。
- -i或–interfaces 显示网络界面信息表单。
- -p或–programs 显示正在使用Socket的程序识别码和程序名称。
|