我的TL-WR706N迷离路由器竟然坏掉了,fuck,一个路由器还能坏掉!
由于台式机么有无线网卡,然后布线又太麻烦,恰好手头有一个树莓派,可以把它当作无线网卡使用。
我的树莓派具体型号是3B+,有一个伪千兆网口,并且支持2.5/5G双频WiFi AC,待机功耗按均值5W计算,非常合适当作路由器使用,而且保留Linux系统本身,不需要刷特别的OS,一机多用,简直不要太爽。
连接WiFi
nano /etc/wpa_supplicant/wpa_supplicant.conf
network={ ssid=“waveshare_1013” psk="waveshare" }
wpa_cli -i wlan0 reconfigure
ifdown/ifconfig wlan0
ifup/ifconfig wlan0
配置网桥
apt install bridge-utils -y
brctl addbr br-lan
brctl addif br-lan eth0
ifconfig br-lan 192.168.88.1 up
ifconfig eth0 0.0.0.0 up
开启IP转发
nano /etc/sysctl.conf
net.ipv4.ip_forward = 1
sysctl -p
或者
sysctl net.ipv4.ip_forward=1
配置iptables
iptables -F (Delete all rules in chain or all chains!!!!)
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
安装DHCP
apt install dnsmasq -y
more /etc/dnsmasq.conf
echo 'dhcp-range=192.168.88.50,192.168.88.150,255.255.255.0,72h' >> /etc/dnsmasq.conf #这里IP的网段跟之前配置的需要一致
配置持久化 nano /home/pi/nat_script
#!/bin/bash
brctl addbr br-lan
brctl addif br-lan eth0
ifconfig br-lan 192.168.88.1 up
ifconfig eth0 0.0.0.0 up
sysctl net.ipv4.ip_forward=1
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
创建系统服务,并开机启动一次
cat /etc/systemd/system/nat_bridge.service
[Unit]
Description=Newbridge for nat Service
After=network.target
[Service]
Type=oneshot
ExecStart=/home/pi/nat_script
[Install]
WantedBy=multi-user.target
systemctl enable nat_bridge.service
one more things
防火墙规则持久化,也可以用iptables-persistent实现
apt-get install iptables-persistent
service netfilter-persistent save
service netfilter-persistent reload
cat /etc/iptables/rules.v4
iptables -t nat -L -n --line-numbers
Pages: 1 2