IMX6ULL開發板設置靜態IP

編輯 /etc/network/interface文件

vi /etc/network/interfaces
//可以看到如下內容# Wired or wireless interfaces
auto eth0
iface eth0 inet dhcp
iface eth1 inet dhcp

這段代碼表示網卡設置動態獲取IP,我們把eth0註釋掉。

# Wired or wireless interfaces
auto eth0
#iface eth0 inet dhcp  //註釋這一行
iface eth1 inet dhcp

然後在文件內添加如下指令

iface eth0 inet static  //設置eth0爲靜態的IP地址方式
address 192.168.1.111   //你的IP地址
netmask 255.255.255.0   //子網掩碼
gateway 192.168.1.1     //網關
broadcast 192.168.1.255 //廣播

整個文件如下:

# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
 
# The loopback interface
auto lo
iface lo inet loopback
 
# Wireless interfaces
iface wlan0 inet dhcp
        wireless_mode managed
        wireless_essid any
        wpa-driver wext
        wpa-conf /etc/wpa_supplicant.conf
 
iface atml0 inet dhcp
 
# Wired or wireless interfaces
auto eth0
#iface eth0 inet dhcp
iface eth1 inet dhcp
 
iface eth0 inet static
address 192.168.1.111
netmask 255.255.255.0
gateway 192.168.1.1
broadcast 192.168.1.255
 
# Ethernet/RNDIS gadget (g_ether)
# ... or on host side, usbnet and random hwaddr
iface usb0 inet static
        address 192.168.7.2
        netmask 255.255.255.0
        network 192.168.7.0
        gateway 192.168.7.1
 
# Bluetooth networking
iface bnep0 inet dhcp

重啓網卡

/etc/init.d/networking restart

設置開機自動啓動

在/etc/init.d/rc下修改
在文件的最後加入以下命令就可以了

ifconfig eth0 192.168.1.111 netmask 255.255.255.0
route add default gw 192.168.1.1

也可以通過以下命令追加到文件中:

echo "ifconfig eth0 192.168.xxx.xxx netmask 255.255.255.0" | tee -a /etc/init.d/rc
echo "route add default gw 192.168.xxx.1" | tee -a /etc/init.d/rc
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章