Nanopc使用USB网卡做简易路由器

来源:互联网 发布:ext ajax 参数类型json 编辑:程序博客网 时间:2024/05/22 14:26

一张集成网卡eth0,一张usb扩展网卡eth1;usb网卡为AX系列,其驱动已经安装在内核里面了。eth0连接外网,eth1连接内网,实现eth1内网可以访问外网,需要进行3个步骤;1.编辑网卡配置文件;2.修改dnsmasq.conf利用dnsmasq服务的dhcp功能开启dhcp自动分配ip;3.通过防火墙开启eth1与eth0之间的转发;
注:usb网卡在系统reboot重启时不会自动重启,需要拔插一次才能使用;正确重启步骤为:系统重启reboot->拔插usb网卡->查看ifconfig是否有eth1信息如果没有ifconfig eth1 up->启动 dnsmasq服务->开启防火墙转发
1.编辑/network/interface文件为:
vi /etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)# Include files from /etc/network/interfaces.d:source-directory /etc/network/interfaces.dauto loiface lo inet loopbackauto eth0allow-hotplug eth0iface eth0 inet dhcpauto eth1allow-hotplug eth1iface eth1 inet staticaddress 192.168.2.1netmask 255.255.255.0allow-hotplug wlan0iface wlan0 inet manualwpa-roam /etc/wpa_supplicant/wpa_supplicant.confiface default inet dhcp

2.编辑dnsmasq.conf分配一段ip地址192.168.2.1
mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
vi /etc/dnsmasq.conf

interface=lo,eth1no-dhcp-interface=lodhcp-range=192.168.2.20,192.168.2.254,255.255.255.0,12h

启动dnsmasq服务
service dnsmasq start
3.利用iptables实现防火墙eth0-eth1端口转发

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADEiptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPTiptables -A FORWARD -i eth1 -o eth0 -j ACCEPT