嵌入式网络IP设置方案

参考文档:

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通网关和外网。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值