Ubuntu10.10网卡配置文件重启失效怎么办?

发布时间:2020-01-28编辑:脚本学堂
本文介绍了ubuntu 10.10网卡配置文件重启后失效的解决方法,需要的朋友参考下。

环境:ubuntu 10.10
目标:配置网卡启动时加载iptables规则

网上提到的各种操作:
sh -c "iptables-save > /etc/iptables.rules"
vi /etc/network/interfaces
 

复制代码 代码示例:
## 目标网卡下增加一条命令
## pre-up iptables-restore < /etc/iptables.rules

但是,经测试发现。重启后这些配置会丢失,查看这个文件头会发现。
 

复制代码 代码示例:
# This configuration file is auto-generated.
# WARNING: Do not edit this file, your changes will be lost.
# Please create/edit /etc/network/interfaces.head and /etc/network/interfaces.tail instead,
# their contents will be inserted at the beginning and at the end
# of this file, respectively.
#
# NOTE: it is NOT guaranteed that the contents of /etc/network/interfaces.tail
# will be at the very end of this file.
 

文件写得很明确,/etc/network/interfaces是自动生成的。
如果需要自定义配置,那就创建/etc/network/interfaces.head或/etc/network/interfaces.tail。其中/etc/network/interfaces.tail并不推荐。

例子:
 

复制代码 代码示例:
auto venet0:0
iface venet0:0 inet static
address 184.22.224.125
netmask 255.255.255.0
pre-up iptables-restore < /etc/iptables.rules