这是我的/etc/network/interfaces
配置:
auto lo
iface lo inet loopback
iface eth0 inet static
address 192.168.1.2/24
gateway 192.168.1.1
post-up echo "script run" > /home/user/ifuptest.txt
当我关闭 iface 然后再次打开时,ip link set eth0 down
界面正常显示,但主目录中ip link set eth0 up
没有创建新的文本文件。ifuptest.txt
答案1
脚本的改进:
在/etc/网络/接口:
auto lo
iface lo inet loopback
iface eth0 inet static
address 192.168.1.2/24
gateway 192.168.1.1
post-up /bin/myscript.sh
/bin/myscript.sh:
#!/bin/sh
echo "script run" > /home/user/ifuptest.txt
使可执行文件:
chmod +x /bin/myscript.sh
设置/启动接口时的故障排除:
尝试这个:
ip link set dev eth0 down
ip link set dev eth0 up
然后:
ifconfig eth0 down
ifconfig eth0 up
并检查行为的差异。