Wifi

WLAN 已連接但無法訪問網際網路

  • August 23, 2016

我有一個 linux 盒子,有乙太網、wlan STA/客戶端和 wlan 接入點。這是通過乙太網連接的網際網路,我可以通過 ssh 登錄到盒子。但我希望像無線路由器一樣使用盒子,並能夠通過使用智能手機連接到網際網路。我可以將我的手機連接到 wifi,但它無法訪問網際網路。

這是我的界面:

eth0是乙太網

eth1並且eth2是 WLAN

# ifconfig
br0       Link encap:Ethernet  HWaddr 00:15:BC:22:17:20
         inet addr:10.10.1.116  Bcast:10.10.1.255  Mask:255.255.255.0
         inet6 addr: fe80::215:bcff:fe22:1720/64 Scope:Link
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:6377 errors:0 dropped:608 overruns:0 frame:0
         TX packets:615 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:0
         RX bytes:865911 (845.6 KiB)  TX bytes:59751 (58.3 KiB)

eth0      Link encap:Ethernet  HWaddr 00:15:BC:22:17:20
         inet6 addr: fe80::215:bcff:fe22:1720/64 Scope:Link
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:6417 errors:0 dropped:6 overruns:0 frame:0
         TX packets:623 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000
         RX bytes:985364 (962.2 KiB)  TX bytes:60399 (58.9 KiB)

eth1      Link encap:Ethernet  HWaddr 00:15:BC:22:17:21
         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)

eth2      Link encap:Ethernet  HWaddr 02:15:BC:22:17:21
         inet addr:192.168.2.10  Bcast:192.168.2.255  Mask:255.255.255.0
         inet6 addr: fe80::15:bcff:fe22:1721/64 Scope:Link
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:502 errors:0 dropped:3 overruns:0 frame:0
         TX packets:236 errors:0 dropped:8 overruns:0 carrier:0
         collisions:0 txqueuelen:1000
         RX bytes:44998 (43.9 KiB)  TX bytes:24874 (24.2 KiB)

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:164 errors:0 dropped:0 overruns:0 frame:0
         TX packets:164 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:0
         RX bytes:13525 (13.2 KiB)  TX bytes:13525 (13.2 Ki

二)

這是/etc/network/interfaces文件:

auto lo
iface lo inet loopback

iface eth0 inet manual

iface eth1 inet dhcp

iface eth2 inet dhcp

iface br0 inet dhcp
hostname gw-143A
  bridged_ports  eth0

無線的:

# iwconfig
tap0      no wireless extensions.

lo        no wireless extensions.

br0       no wireless extensions.

eth2      IEEE 802.11-bgn  Mode:Master  Frequency:2.457 GHz

eth1      IEEE 802.11-bgn  ESSID:""
         Mode:Managed  Frequency:2.437 GHz  Access Point: Not-Associated
         Bit Rate:0 kb/s
         RTS thr:off   Fragment thr:off
         Encryption key:9F64-0D78-CCAB-A8 [3]
         Power Management:off
         Link Quality:0  Signal level:0  Noise level:0
         Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
         Tx excessive retries:0  Invalid misc:0   Missed beacon:0

sit0      no wireless extensions.

eth0      no wireless extensions.

為了讓您的 linux 機器充當 WLAN 接入點,您需要:

  • 確保您的無線網卡使用支持 AP 的驅動程序。的輸出lsmod | grep 80211通常會有所幫助。如果您的驅動程序不支持 AP 模式,則您必須獲得一個支持的新 WLAN 適配器。
  • 確保您的核心支持IP 轉發並啟用它。這通常通過echo 1 > /proc/sys/net/ipv4/ip_forward以 root 身份執行來完成。
  • 配置路由表以將網路數據包轉發br0eth2

sudo iptables -t nat -A POSTROUTING -o br0 -j MASQUERADE

sudo iptables -A FORWARD -i br0 -o eth2 -m state --state RELATED,ESTABLISHED -j ACCEPT

sudo iptables -A FORWARD -i eth2 -o br0 -j ACCEPT

  • 安裝和配置接入點管理軟體
  • 配置一個 DHCP 伺服器,該伺服器將為您的電話分配一個 IP 地址(如果尚未完成)。

引用自:https://unix.stackexchange.com/questions/305189