参考文档:
1. Two utilities for network configuration: connman and systemd-networkd
2. 无线模块移植的必读资料
3. 开机自启动配置
静态IP设置方案
有线连接
a. 设置静态IP,通过systemd启动脚本
例:开机静态配置IP (本项目选用其他方案)
1.先在 /etc/systemd/system/ 下创建以 ×××.service 结尾的文件脚本
[Unit]
Description=setted static IP in system started with network.
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/configip.sh
[Install]
WantedBy=multi-user.target
2.将启动程序configip.sh放在/usr/bin/(可执行程序)
其中configip.sh内容为:
#!/bin/sh
#set eth0 mac address
ifconfig eth0 hw ether 00:14:2D:4E:52:DA
#set eth0 ip
ifconfig eth0 192.168.2.8 up
#add route
route add default gw 192.168.2.1
3.systemctl enable ×××.service 开机使能该服务
b. 通过connman工具,具体步骤参考上述参考文档:
connmanctl services
connmanctl services ethernet_00142d259a48_cable
connmanctl
connmanctl> config ethernet_00142d259a48_cable --ipv4 manual 192.168.10.2 255.255.255.0 192.168.10.1
connmanctl> exit
connmanctl config ethernet_00142d259a48_cable --nameservers 8.8.8.8
[动态IP可添加]
connmanctl> config ethernet_00142d259a48_cable --ipv4 dhcp
无线连接
无线连接:
udhcpc -i eth0 (连接无线时)
udhcpd /etc/udhcpd.conf (AP模式,可看本项目)
大/小型服务器动态IP分配
dhclient / dhcpd 命令,适合在大型的系统上使用
udhcpc / udhcpd 命令,适合在嵌入式系统上使用
自动分配IP时,可避免相同网段的IP被占用,上述服务需手动移植。
注意事项
1.通过ifconfig设置IP后(有线连接方案a),电脑与开发板可以相互ping通,但开发板不能ping通路由器(网关)和外网
2.子网掩码和网关不变时,改变静态IP,上述问题没有出现。
原因:
进入路由器时,发现需设置的IP已经被占用(尽管没设置之前无法ping通),导致再次设置 时出现冲突,无法ping通网关和外网。