Wireless Internet router bridging program
Scenarios
condition:
First, we have an Internet access Wi-Fi, we assume for the wifi.
Now we have two routers A and B, two servers SA and SB, connected to a router on each server.
aims:
By connecting a computer to the A, we can log on to the server SA, and the Internet in SA.
Open A router configuration page, I used here is tplink,
Setup Mode
Click Next, then we choose it to be bridged wifi
Open the list wifi, wifi connection that we want
Then set the name and the secret encryption key, click Next, you might see, it is because you choose to use that wifi is 13 channels, so you need to put your router is set to channel 13
OK, modified to channel 13
And then click Next, enter the router password
Prompted to restart
After waiting for the reboot is complete, the router A landing page management
OK
A bridge to router wifi, configuration.
Next, configure the LAN Server A
SA has four Ethernet ports, we assume that the fourth network port is dhcp,
A SA through the network cable and the fourth port is connected to the network, the first three port bridge in a bridge network to br0.
xxx@hostname:~$ ifconfig br0 Link encap:Ethernet HWaddr 00:e0:4c:68:35:cb inet addr:192.168.10.10 Bcast:192.168.10.255 Mask:255.255.255.0 UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) p1p1 Link encap:Ethernet HWaddr 00:e0:4c:68:35:cb UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) Memory:d0800000-d081ffff p2p1 Link encap:Ethernet HWaddr 00:e0:4c:68:35:cc UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) Memory:d0700000-d071ffff p3p1 Link encap:Ethernet HWaddr 00:e0:4c:68:35:cd UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) Memory:d0600000-d061ffff p4p1 Link encap:Ethernet HWaddr 00:e0:4c:68:35:ca inet addr:192.168.1.199 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::2e0:4cff:fe68:35ca/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1137 errors:0 dropped:66 overruns:0 frame:0 TX packets:471 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:505826 (505.8 KB) TX bytes:44957 (44.9 KB) Memory:d0900000-d091ffff
我们看到第四个网口分到的IP为192.168.1.199
接下来设置网卡
sudo vi /etc/network/interfaces,以下是我的配置文件,这台机器有四个网口,p1p1,p2p1 , p3p1 ,p4p1,
其中前三个桥接为一个网桥br0,p4p1则设置成了固定IP 192.168.1.199,
并且配置文件中p4p1的网关要设置成和wifi的网关一致,我这里是192.168.199.1
文件内容:
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo br0 iface lo inet loopback iface p1p1 inet manual iface p2p1 inet manual iface p3p1 inet manual #iface p4p1 inet manual auto p4p1 iface p4p1 inet static address 192.168.1.199 gateway 192.168.1.1 netmask 255.255.255.0 # Bridge setup iface br0 inet static bridge_ports p1p1 p2p1 p3p1 address 192.168.10.10 broadcast 192.168.10.255 netmask 255.255.255.0 gateway 192.168.10.1
然后,我们重启服务器,使网络配置生效。
我们通过电脑连接到A,然后再远程到服务器SA上,然后尝试看看能不能上网。
xxx@hostname:~$ ping www.baidu.com PING www.a.shifen.com (39.156.66.18) 56(84) bytes of data. 64 bytes from 39.156.66.18: icmp_seq=1 ttl=52 time=14.5 ms 64 bytes from 39.156.66.18: icmp_seq=2 ttl=52 time=11.5 ms 64 bytes from 39.156.66.18: icmp_seq=3 ttl=52 time=61.6 ms 64 bytes from 39.156.66.18: icmp_seq=4 ttl=52 time=153 ms 64 bytes from 39.156.66.18: icmp_seq=5 ttl=52 time=38.4 ms 64 bytes from 39.156.66.18: icmp_seq=6 ttl=52 time=135 ms ^C --- www.a.shifen.com ping statistics --- 6 packets transmitted, 6 received, 0% packet loss, time 5005ms rtt min/avg/max/mdev = 11.505/69.104/153.322/55.871 ms
相关命令:
demo: #The primary network interface auto eth0 iface eth0 inet static address 192.168.1.199 gateway 192.168.1.1 netmask 255.255.255.0 #network 192.168.1.0 #broadcast 1921.68.1.255 设置网卡eth0的IP地址和子网掩码 sudo ifconfig eth0 192.168.2.1 netmask 255.255.255.0 重启网络服务(若不行,请重启ubuntu:sudo reboot) sudo /etc/init.d/networking restart Ubuntu14.04 设置网关 sudo route add default gw 192.168.1.1 #查看路由信息 higgs@HiggsDynamics:~$ route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default 192.168.1.1 0.0.0.0 UG 0 0 0 p4p1 192.168.1.0 * 255.255.255.0 U 0 0 0 p4p1 192.168.10.0 * 255.255.255.0 U 0 0 0 br0