我的目的很简单。我想将以太网 eth0 上的互联网共享给充当接入点的 wlan0。但我已经在 eth0 和 tap0 之间建立了桥接 br-lan。所以我无法将 br0 与 eth0 和 wlan0 桥接。这是我的
/etc/网络/接口
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet manual
address 0.0.0.0
allow-hotplug wlan0
iface wlan0 inet manual
address 0.0.0.0
auto br-lan
iface br-lan inet dhcp
bridge-ports eth0
auto br0
iface br0 inet static
address 192.168.2.1
netmask 255.255.255.0
network 192.168.2.0
broadcast 192.168.2.255
bridge_ports eth0 wlan0
bridge_fd 1
bridge_hello 1
bridge_stp on
是否配置
br0 Link encap:Ethernet HWaddr 00:17:7c:22:88:18
inet addr:192.168.2.1 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::217:7cff:fe22:8818/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:30 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:4901 (4.9 KB)
br-lan Link encap:Ethernet HWaddr 00:04:9f:04:10:39
inet addr:192.168.1.125 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fd00:aaaa::204:9fff:fe04:1039/64 Scope:Global
inet6 addr: fd45:6807:17db:0:204:9fff:fe04:1039/64 Scope:Global
inet6 addr: fd00:aaaa::85c:ae5a:130d:40f/64 Scope:Global
inet6 addr: fe80::204:9fff:fe04:1039/64 Scope:Link
inet6 addr: fd45:6807:17db:0:85c:ae5a:130d:40f/64 Scope:Global
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1039 errors:0 dropped:0 overruns:0 frame:0
TX packets:161 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:393281 (393.2 KB) TX bytes:23516 (23.5 KB)
eth0 Link encap:Ethernet HWaddr 00:04:9f:04:10:39
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1177 errors:0 dropped:1 overruns:0 frame:0
TX packets:214 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:478095 (478.0 KB) TX bytes:32178 (32.1 KB)
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:86 errors:0 dropped:0 overruns:0 frame:0
TX packets:86 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:6483 (6.4 KB) TX bytes:6483 (6.4 KB)
tap0 Link encap:Ethernet HWaddr 7e:e0:12:05:00:39
inet6 addr: fe80::7ce0:12ff:fe05:39/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:28 errors:0 dropped:0 overruns:0 frame:0
TX packets:728 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:4385 (4.3 KB) TX bytes:282726 (282.7 KB)
wlan0 Link encap:Ethernet HWaddr 00:17:7c:22:88:18
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:32 errors:0 dropped:0 overruns:0 frame:0
TX packets:43 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:3724 (3.7 KB)
/etc/hostapd/hostapd.conf
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
macaddr_acl=0
auth_algs=3
ignore_broadcast_ssid=0
# 802.11n related stuff
ieee80211n=1
noscan=1
ht_capab=[HT40+][SHORT-GI-20][SHORT-GI-40]
#WPA2 settings
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
# Most modern wireless drivers in the kernel need driver=nl80211
#driver=nl80211
driver=rtl871xdrv
max_num_sta=8
beacon_int=100
wme_enabled=1
wpa_group_rekey=86400
device_name=RTL8192CU
manufacturer=Realtek
# set proper interface
interface=wlan0
bridge=br0
hw_mode=g
# best channels are 1 6 11 14 (scan networks first to find which slot is free)
channel=6
# this is the network name
ssid=***
wpa_passphrase=***
/etc/dnsmasq.d/dhcp.conf
dhcp-range=192.168.2.100,192.168.2.200,255.255.255.0,12h
dhcp-option=option:router,192.168.2.1
dhcp-option=option:dns-server,192.168.2.1
dhcp-authoritative
路线
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 br-lan
192.168.1.0 * 255.255.255.0 U 0 0 0 br-lan
192.168.2.0 * 255.255.255.0 U 0 0 0 br0
brctl 显示
bridge name bridge id STP enabled interfaces
br-lan 8000.00049f041039 no eth0
tap0
br0 8000.00177c228818 yes wlan0
路由
default via 192.168.1.1 dev br-lan
192.168.1.0/24 dev br-lan proto kernel scope link src 192.168.1.125
192.168.2.0/24 dev br0 proto kernel scope link src 192.168.2.1
因此,我能够从 Linux 机器访问互联网并通过 br0(wlan0)托管 AP,并将我的手机连接到它并获取 IP 并从我的手机 ping 192.168.2.1。
据我所知,eth0 无法与 br0 桥接,因为它已经与 br-lan 桥接。那么我如何才能让 br0 或 wlan0(wifi AP)上网呢?
我可以 ping 通两个网络。
ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.856 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.816 ms
ping 192.168.2.149
PING 192.168.2.149 (192.168.2.149) 56(84) bytes of data.
64 bytes from 192.168.2.149: icmp_seq=1 ttl=64 time=5.46 ms
64 bytes from 192.168.2.149: icmp_seq=2 ttl=64 time=4.58 ms