RaspberryPi作无线路由器

前一段时间升级了ubuntu之后,EDUP的无线网卡一连接wifi整个系统就会crash,导致无法正常上网,刚好小Pi闲置在旁,于是将它当作路由器先用起来,目的很简单,让Pi连上家里的wifi,然后让服务器通过Pi的有线网口路由出局。

操作比较简单,首先将Pi的有线网卡地址设置为静态,并且配置好IP地址,通过编辑/etc/network/interfaces实现,修改eth0的属性如下:

auto eth0
iface eth0 inet static
address 192.168.137.1
netmask 255.255.255.0

然后编辑/etc//rc.local,在exit 0之前添加修改iptables转发的策略:

iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

如上配置完之后,每次Pi重启都能自动修改iptables(PS:正常情况下修改完iptables之后可以通过-L选项查看并且使用iptables-save进行保存,但是在Pi上配置完之后并不显见可用,所以临时通过修改启动项的方式来操作)。

接下来就是配置ubuntu服务器,因为系统默认安装了network-manager,所以就用它将本地的有线网卡配置成静态地址,IP地址保证和Pi在同一个网段,网关就是Pi自己的地址192.168.137.1:

然后修改ubuntu服务器上的dns解析文件/etc/resolvconf/resolv.conf.d/base,添加如下内容:

nameserver 192.168.137.1
nameserver 8.8.8.8
nameserver 114.114.114.114

ubuntu上无需手动配置路由信息,便可以正常访问internet了。

RaspberryPi作无线路由器》有1个想法

  1. I was glad to see this report. More and more, the promise of efficient, environmentally beneficial industrial-scale wind energy is being seen as the smkim-and-eorrors illusion it is. I will be happy to see this awareness spread in the United States (and my state of North Dakota), as is inevitable.

回复 Jeannie 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据