Linux系统下将电脑配置成路由器


1.ubantu下将电脑配置成路由器(有线方式)

准备两台电脑PCA:PCA配置成路由器, Ubantu系统

PCB:PCB作为终端,Win7系统

(1).配置两张网卡信息:eth0(有线的以太网卡) 和 wlan0(无线网卡):$/etc/network/interface编辑如下信息

auto lo

                        iface lo inet loopback

                       

                        auto wlan0

                        iface wlan0 inet static

                        address 192.168.1.102

                        gateway 192.168.1.1

                        netmask 255.255.0.0

                       

                        auto eth0

                        iface eth0 inet static

                        address 192.168.6.1

                        netmask 255.255.255.0

                        network 192.168.6.0

                        broadcast 192.168.6.255


(2).执行ipv4转发脚本router.sh

#!/bin/sh

echo 1 > /proc/sys/net/ipv4/ip_forward
cat /proc/sys/net/ipv4/ip_forward
ifconfig eth0 192.168.6.1 up
iptables -t nat -F
iptables -t nat -A POSTROUTING -s 192.168.6.0/24 -o wlan0 -j MASQUERADE  

(3).如果此时PCA无法上网,看一下是否配置默认网关:$ route -n

如果没有默认网关,添加默认网关:route add default gw 192.168.1.1


(4).用网线将PCA和PCB连接起来,禁掉PCB的无线,准备测试PCB是否能通过PCA上网

手动修改PCB的ip地址为:192.168.6.10

网关:192.168.6.1

子网掩码:255.255.255.0

DNS:8.8.8.8 (如果上面配置好了PCB依然不能上网,可能是DNS解析问题)

(5).在PCA上搭建DHCP服务器

第(4)步中我们总是需要手动给PCB配置ip,比较麻烦,我们可以通过DHCP让它自动获取ip,方法如下:

安装dhcp服务器: $sudo apt-get install isc-dhcp-common isc-dhcp-server

(i)修改/etc/default/isc-dhcp-server

                INTERFACES="eth0"

(ii)修改/etc/dhcp/dhcpd.conf

                subnet 192.168.6.0 netmask 255.255.255.0 {

                  range 192.168.6.100 192.168.6.200;

                  option routers 192.168.6.1;

                  option broadcast-address 192.168.6.255;

                  default-lease-time 600;

                  max-lease-time 7200;

                }

参考博客:http://www.blogjava.net/canvas/articles/router-dhcp.html


2.ubantu下将电脑配置成路由器(无线热点方式)待更新...


你可能感兴趣的:(Linux)