需求:开机使能eth0,并设置IP为固定值.
做法:修改/etc/network/interfaces
在文件只有2行的下面,增加了如下的内容:
# interface file auto-generated by buildroot
auto lo
iface lo inet loopback
// 上面是默认的内容,下面是新增的内容,上下之间需要一个空行隔开
// 接口顶格写,属性的前面有一个tab的缩进
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.113
network 192.168.1.0
netmask 255.255.255.0
broadcast 192.168.1.255
gateway 192.168.1.1
上面的语句, 等效于
ifconfig eth0 up
ifconfig eth0 192.168.1.113
route add default gw 192.168.1.1
这样就无需开机输入上面的内容,每次开机自己去设置网络就好了.
如果是想开机就启用DHCP的话,按照下面的方式来修改.
# interface file auto-generated by buildroot
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp
说明:
- interfaces的语法是特有的,不能直接在这里直接使用shell命令,如ifconfig eth0 up之类的.
- 也不要将 > ifconfig eth0 up > 放在/et/rcS 里.