我有一个 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.
答案1
为了让您的 Linux 盒子充当 WLAN 接入点,您需要:
- 确保您的无线网卡使用支持AP的驱动。的输出
lsmod | grep 80211
通常会有所帮助。如果您的驱动程序不支持 AP 模式,则您必须购买一个支持 AP 模式的新 WLAN 适配器。 - 确保你的内核支持IP转发并启用它。这通常是通过
echo 1 > /proc/sys/net/ipv4/ip_forward
以 root 身份运行来完成的。 - 配置路由表以将网络数据包转发
br0
至eth2
:
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 地址(如果尚未完成)。