我有 Beaglebone Black,安装了 Debian 7.11 Wheezy
我有从 Beaglebone 创建的网络,并且 Beaglebone IP 地址设置为静态:192.168.20.1
这是我的/etc/network/interfaces
文件:
# The wireless network interface
#allow-hotplug wlan0
auto wlan0
#iface wlan0 inet dhcp
# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface wlan0 inet static
address 192.168.20.1
netmask 255.255.255.0
当我使用静态 IP 192.168.20.1 时,我还运行 hostapd 和 isc-dhcpd-server 服务,以便创建用户可以连接到 beaglebone 的网络:我的 isc-dhcp-server 设置为放置 192.168.20.3-254 中的 IP 地址这是我的dhcpd.conf
文件:
subnet 192.168.20.0 netmask 255.255.255.0 {
range 192.168.20.3 192.168.20.254;
option broadcast-address 192.168.20.255;
default-lease-time 600;
max-lease-time 7200;
}
我在 deamon.log 文件中发现由于某种原因 dhclient 可能更改了 beaglebone IP 地址
Mar 20 11:36:01 smartgrow dhclient: DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 4
Mar 20 11:36:01 smartgrow rc.local[717]: sudo: unable to resolve host smartgrow
Mar 20 11:36:02 smartgrow dhclient: DHCPREQUEST on wlan0 to 255.255.255.255 port 67
Mar 20 11:36:02 smartgrow dhclient: DHCPOFFER from 192.168.20.1
Mar 20 11:36:02 smartgrow dhclient: DHCPACK from 192.168.20.1
Mar 20 11:36:02 smartgrow samba[2929]: Reloading /etc/samba/smb.conf: smbd only.
Mar 20 11:36:02 smartgrow dhclient: bound to 192.168.20.5 -- renewal in 281 seconds.
Mar 20 11:36:04 smartgrow ntpd[864]: Listen normally on 7 wlan0 192.168.20.5 UDP 123
编辑:dhclient 在 /etc/rc.local 上做的事情是在该脚本上运行的
#!/bin/sh
if [ -f /etc/wpa_supplicant/wpa_supplicant.conf ] # If file exist
then
version=$(sudo /bin/cat /home/network/option.gse)
if [ "$version" = "static" ]
then
sudo cp /home/scripts/user /etc/network/interfaces
else
sudo cp /home/scripts/dynamic /etc/network/interfaces
fi
else
sudo cp /home/scripts/static /etc/network/interfaces
fi
/etc/init.d/isc-dhcp-server stop
/etc/init.d/hostapd stop
ip addr flush dev wlan0
ip link set wlan0 up
/etc/init.d/networking restart
ip=$(/sbin/ifconfig wlan0 | grep 'inet addr' | cut -d: -f2 | awk '{print $1}') # Get IP address for wlan0
case "$ip" in
192.168.20.* | "")
{
sudo cp /home/scripts/static /etc/network/interfaces
/etc/init.d/hostapd stop
ifconfig wlan0 192.168.20.1/24
ip addr flush dev wlan0
ip link set wlan0 up
/etc/init.d/networking restart
sleep 10
wifis=$(iwlist wlan0 scann | grep ESSID | cut -d: -f2)
echo $wifis > /var/www/smart-grow-controller/storage/cache/wifi-list
/etc/init.d/isc-dhcp-server restart
/etc/init.d/hostapd restart
};;
*)
{
ips=$(sudo arp-scan --interface=wlan0 --localnet| awk '{print $1}'|tail -n +3|head -n -2)
first=$(echo $ips | cut -d' ' -f1)
if ping -c 1 -W 1 "$first"
then
/etc/init.d/isc-dhcp-server stop
/etc/init.d/hostapd stop
else
sudo cp /home/scripts/static /etc/network/interfaces
ifconfig wlan0 192.168.20.1/24
ip addr flush dev wlan0
ip link set wlan0 up
/etc/init.d/networking restart
sleep 10
wifis=$(iwlist wlan0 scann | grep ESSID | cut -d: -f2)
echo $wifis > /wifi-list-path/wifi-list
/etc/init.d/networking restart
/etc/init.d/isc-dhcp-server restart
/etc/init.d/hostapd restart
fi
};;
esac
/etc/init.d/samba restart
ip=$(/sbin/ifconfig wlan0 | grep 'inet addr' | cut -d: -f2 | awk '{print $1}')
mask=$(/sbin/ifconfig wlan0 | awk '/Mask:/{ print $4; }')
gateway=$(ip route show default | awk '/default/ {print $3}')
我的问题是:为什么某些东西(dhcp)会改变我的静态IP地址?当我设置静态IP地址不改变时如何解决这个问题?