由于开发板需要连接网络上网,可是开发板却没有无线网卡,然后又离路由器比较远,所以想到使用笔记本的无线网卡wlan0和有线网卡eth0之间做通信,然后让开发板接入笔记本的eth0接口上网。
1.加载有关的kernel模块
modprobe ipt_MASQUERADE
清空防火墙规则,确保包数据不被阻塞;
iptables –F 或者 iptables --flush
开启两接口之间的NAT功能;
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
最后我们要开启kernel到两个接口之间的前向包;
echo 1 > /proc/sys/net/ipv4/ip_forward
在ubuntu系统下,vi /etc/network/options中确保
ip_forward=yes
然后
/etc/init.d/network-manager restart
2.开启DHCP服务器:
目前为止,我们已经能访问笔记本的有线网络,但是只能通过手动设置IP才能进行通信,接下来我们需要让我们的AP可以为连接他的设备动态获取IP。
需要使用dnsmasq工具包,vi /etc/dnsmasq.conf 其配置为:
interface=eth0
dhcp-range=192.168.1.100,192.168.1.200,255.255.255.0,6h
listen-address=127.0.0.1
port=5353
保存之后重启:
/etc/init.d/dnsmasq restart
到此,连入该有线接口的设备可以自动获取IP了。
我的最后需要重启一下 systemd-resolved.service 服务。
参考自:http://www.cnblogs.com/aixin0813/archive/2013/09/05/3303223.html
直接写一个 shell 脚本,每次执行一下:
#/bin/sh
#1.加载有关的kernel模块
modprobe ipt_MASQUERADE
#2.清空防火墙规则,确保包数据不被阻塞;
iptables --flush
#3.开启两接口之间的NAT功能;
iptables -t nat -A POSTROUTING -o wlp3s0 -j MASQUERADE
#4.开启kernel到两个接口之间的前向包;
echo 1 > /proc/sys/net/ipv4/ip_forward
#5.vi /etc/network/options中确保,ip_forward=yes;然后
/etc/init.d/network-manager restart
#6.vi /etc/dnsmasq.conf 中添加
#interface=enp4s0
#dhcp-range=192.168.6.100,192.168.6.109,255.255.255.0,6h
#listen-address=127.0.0.1
#port=5353
#然后
/etc/init.d/dnsmasq restart
#7.重启解析域名服务
systemctl restart systemd-resolved.service