您现在的位置是:首页-计算机知识计算机知识

liunx如何绑定ip和mac地址?

云祈yc2026-12-03 07:20:13【计算机知识】

简介liunx如何绑定ip和mac地址?绑定ip和mac地址,可以防范arp,以下是方法,设置完以后,每次开机自动绑定。查看本机ip和mac地址和网卡名,ip addr show,设置开机自启...


绑定ip和mac地址,可以防范arp,以下是方法,设置完以后,每次开机自动绑定。

1.创建服务文件:
debian命令
nano /etc/systemd/system/arp-bind.service

ubuntu命令
sudo nano /etc/systemd/system/arp-bind.service


-------------------------------------------------------------------
2.写入以下内容(修改ip和mac):

[Unit]
Description=Static ARP Binding Service
After=network.target network-online.target
Wants=network-online.target

[Service]
Type=oneshot
ExecStart=/bin/bash -c "/usr/sbin/ip neigh replace 你的局域网ip lladdr 你的局域网mac dev 你的网卡名字 nud permanent"
ExecStart=/bin/bash -c "/usr/sbin/ip neigh replace 网关ip lladdr 网关mac dev 你的网卡名字 nud permanent"
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

-------------------------------------------------------------------
3.设置开机自启
systemctl daemon-reload
systemctl enable arp-bind.service
systemctl start arp-bind.service



--------------------查看本机ip和mac地址-------------------------
查看本机ip和mac地址和网卡名
ip addr show

如图:


--------------------查看网关ip和mac地址-------------------------
查看网关ip(default那一行就是网关的ip地址)
ip route

查看网关mac(lladdr后面的就是网关mac地址)
ping - 2 网关ip
ip neigh show 网关ip

--------------------其他命令-------------------------
查看是否活跃
systemctl status arp-bind.service

查看是否绑定
ip neigh show




很赞哦!