树莓派无线转有线

安装必须的软件包

1
apt install -y bridge-utils dnsmasq

添加网桥

1
2
3
4
brctl addbr br0
brctl addif br0 eth0
ifconfig br0 192.168.99.1 up
ifconfig eth0 0.0.0.0 up

打开数据报转发

1
2
3
4
5
echo 1 > /proc/sys/net/ipv4/ip_forward

vim /etc/sysctl.conf
+ net.ipv4.ip_forward = 1
sysctl -p

修改 dnsmasq 配置

1
2
3
vim /etc/dnsmasq.conf
+ dhcp-range=192.168.99.50,192.168.99.100,255.255.255.0,12h
systemctl restart dnsmasq.service

增加 iptbales 启动加载

1
2
3
vim /etc/network/if-pre-up.d/iptables
+ #!/bin/bash
+ iptables-restore < /etc/iptables.rules

修改 iptables

1
2
iptables -t nat -A POSTROUTING -o wlan -j MASQUERADE
iptable-save > /etc/iptables.rules