linux 下网关MAC的查看和配置arp命令

linux 下网关MAC的查看和配置arp命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[root@localhost ~]$ arp
Address HWtype HWaddress Flags Mask Iface
203.171.xx.xx ether 00:D0:D3:3B:23:A8 C eth0
203.171.xx.ab ether 00:16:76:74:45:A1 C eth0
203.171.xx.ac ether 00:16:76:74:45:A1 C eth1
[root@localhost ~]$ arp -a
? (203.171.xx.xx) at 00:D0:D3:3B:23:A8 [ether] . eth0
? (203.171.xx.ab) at 00:16:76:74:45:A1 [ether] . eth0
? (203.171.xx.ac) at 00:16:76:74:45:A1 [ether] . eth1
[root@localhost ~]$ arp -h
Usage:
arp [-vn] [] [-i ] [-a] [] <-Display ARP cache
arp [-v] [-i ] -d [pub][nopub] <-Delete ARP entry
arp [-vnD] [] [-i ] -f [] <-Add entry from file
arp [-v] [] [-i ] -s [temp][nopub] <-Add entry
arp [-v] [] [-i ] -s [netmask ] pub <-''-
arp [-v] [] [-i ] -Ds [netmask ] pub <-''-
=Use '-H ' to specify hardware address type. Default: ether
List of possible hardware types (which support ARP):
strip (Metricom Starmode IP) ash (Ash) ether (Ethernet)
tr (16/4 Mbps Token Ring) tr (16/4 Mbps Token Ring (New)) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) rose (AMPR ROSE) arcnet (ARCnet)
dlci (Frame Relay DLCI) fddi (Fiber Distributed Data Interface) hippi (HIPPI)
irda (IrLAP) x25 (generic X.25) infiniband (InfiniBand)
[root@localhost ~]$ cat /etc/ethers
cat: /etc/ethers: No such file or directory

添加静态项.这个很有用,特别是局域网中中了arp病毒以后:

1
2
$arp -s 123.123.123.111 00:11:56:6F:87:D3
$arp -a #显示 ARP 表.

但是arp -s 设置的静态项在用户登出之后或重起之后会失效,如果想要任何时候都不失效,可以将ip和mac的对应关系写入arp命令默认的配置文件 /etc/ethers中. 例如:

1
2
3
$vi /etc/ethers
arp -s 123.123.123.111 00:11:56:6F:87:D3
$arp -f /etc/ethers