如何创建非临时 wifi 热点?

ask*_*uhn 13 network-manager wireless-access-point network-bridge adhoc hostapd

我想使用带有有线以太网连接 (eth0) 的台式机来操作我的“TP-LINK TL-WN722N”USB Wifi 适配器 (wlan0) 作为我的 Android 连接的非临时(基础架构模式)接入点。

经过大量搜索,我终于找到了一种方法(分布在许多网站上)可以满足我的大部分需求......

依赖项:

 hostapd
 bridge-utils
Run Code Online (Sandbox Code Playgroud)

我修改了“/etc/network/interfaces”

sudo gedit /etc/network/interfaces
Run Code Online (Sandbox Code Playgroud)

包含装有:

# This file describes the network interfaces available on your system
# and how to activate them.

auto lo br0
iface lo inet loopback

allow-hotplug eth0
iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual

# Bridge setup

# for dhcp address
iface br0 inet dhcp
bridge_ports eth0 wlan0

# for static ip
# iface br0 inet static
# bridge_ports eth0 wlan0
# adapt with your network settings
# address 192.168.1.250
# netmask 255.255.255.0
# network 192.168.1.0
# broadcast 192.168.1.255
# gateway 192.168.1.1
# dns-* options are implemented by the resolvconf package, if installed
# dns-nameservers 192.168.1.1
# dns-search localdomain

### Reference ###

# Creating a Wireless Access Point with Debian Linux « Agent Oss (October 31, 2011)
# https://agentoss.wordpress.com/2011/10/31/creating-a-wireless-access-point-with-debian-linux/
Run Code Online (Sandbox Code Playgroud)

我的“/etc/hostapd/hostapd.conf”(我以某种方式设法把自己放在一起)

sudo gedit /etc/hostapd/hostapd.conf
Run Code Online (Sandbox Code Playgroud)

包含:

 ### Guts ###

 interface=wlan0
 bridge=br0
 driver=nl80211

 ### General ###

 ssid=____________________
 hw_mode=g
 channel=1

 ### Security ###

 macaddr_acl=0
 auth_algs=1
 ignore_broadcast_ssid=0     ## 0 visible # 1 hidden ##
 wpa=2
 wpa_passphrase=____________________
 wpa_key_mgmt=WPA-PSK
 wpa_pairwise=TKIP
 rsn_pairwise=CCMP

 ### Reference ###

 ## Created Tuesday, February 14, 2012 ## Ubuntu 11.10/12.04 ##

 # Hostapd Linux Documentation Page
 # http://linuxwireless.org/en/users/Documentation/hostapd

 # Creating a Network Bridge on Ubuntu (January 16th, 2011)
 # http://webserver.linuxportal.nl/?p=422
Run Code Online (Sandbox Code Playgroud)

(我已经删除了这篇文章的安全位)

所有这些都允许我打开一个终端并执行:

 sudo hostapd -B /etc/hostapd/hostapd.conf
Run Code Online (Sandbox Code Playgroud)

拥有一个功能正常的接入点,我的 Android 和所有其他 WiFi 设备都可以连接到该接入点。

除了与其他人共享此方法之外,因为此设置的信息非常稀少;有三个问题可以很好地解决:

  1. 此配置停用网络管理器及其所有功能。单击它时,它会显示“设备不受管理”消息。(不是必需的,但对我来说有点烦人)
  2. 这种方法有时会遇到 IP 地址问题。
  3. 我必须使用终端才能打开 Wifi。(对我来说还好,但对家庭不友好)。 如果有人需要,我想出了如何使用 gksu 和一个简单的脚本制作启动器...

在没有终端的情况下启动 wifi/Hostapd

  1. (为什么网络管理员不能开箱即用??)

提前致谢!我希望所有这些都可以帮助其他人;我以前从未写过教程,对网络几乎一无所知......

也许与网桥有关- 不破坏网络管理器(等等)。

使用 Ubuntu 11.10、12.04 进行测试。

dut*_*hie 5

我不确定如何在不破坏 NM 的情况下执行此操作,但是可以在启动时自动运行并轻松分配 IP 地址(至少我已经使用相同的无线卡进行了管理)。这需要包hostapddnsmasq(不是dnsmasq-base

/etc/hostapd/hostapd.conf:

interface=wlan0
driver=nl80211 # This works on my TL-WN722N

ssid=______

channel=6
hw_mode=g

auth_algs=1
wpa=3
wpa_passphrase=_____
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP
rsn_pairwise=CCMP
Run Code Online (Sandbox Code Playgroud)

/etc/default/hostapd:

# Defaults for hostapd initscript
#
# See /usr/share/doc/hostapd/README.Debian for information about alternative
# methods of managing hostapd.
#
# Uncomment and set DAEMON_CONF to the absolute path of a hostapd configuration
# file and hostapd will be started during system boot. An example configuration
# file can be found at /usr/share/doc/hostapd/examples/hostapd.conf.gz
#
DAEMON_CONF="/etc/hostapd/hostapd.conf"

# Additional daemon options to be appended to hostapd command:-
#   -d   show more debug messages (-dd for even more)
#   -K   include key data in debug messages
#   -t   include timestamps in some debug messages
#
# Note that -B (daemon mode) and -P (pidfile) options are automatically
# configured by the init.d script and must not be added to DAEMON_OPTS.
#
#DAEMON_OPTS=""
Run Code Online (Sandbox Code Playgroud)

/etc/dnsmasq.conf(与维护者版本不同):

--- /etc/dnsmasq.conf.dpkg-dist 2011-09-20 00:28:30.000000000 +0100
+++ /etc/dnsmasq.conf   2012-02-13 21:03:03.713554612 +0000
@@ -82,7 +82,7 @@
 # specified interfaces (and the loopback) give the name of the
 # interface (eg eth0) here.
 # Repeat the line for more than one interface.
-#interface=
+interface=wlan0
 # Or you can specify which interface _not_ to listen on
 #except-interface=
 # Or which to listen on by address (remember to include 127.0.0.1 if
@@ -133,7 +133,7 @@
 # a lease time. If you have more than one network, you will need to
 # repeat this for each network on which you want to supply DHCP
 # service.
-#dhcp-range=192.168.0.50,192.168.0.150,12h
+dhcp-range=192.168.3.10,192.168.3.49,12h

 # This is an example of a DHCP range where the netmask is given. This
 # is needed for networks we reach the dnsmasq DHCP server via a relay
Run Code Online (Sandbox Code Playgroud)

/etc/network/interfaces:

auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet static
    address 192.168.3.1/24
    broadcast 192.168.3.255
Run Code Online (Sandbox Code Playgroud)

/etc/sysctl.conf 补丁(sudo sysctl -p /etc/sysctl.conf更改后运行):

--- sysctl.conf 2012-05-14 18:06:57.514873009 +0100
+++ /etc/sysctl.conf    2012-05-14 18:09:27.122876525 +0100
@@ -25,7 +25,7 @@
 #net.ipv4.tcp_syncookies=1

 # Uncomment the next line to enable packet forwarding for IPv4
-#net.ipv4.ip_forward=1
+net.ipv4.ip_forward=1

 # Uncomment the next line to enable packet forwarding for IPv6
 #  Enabling this option disables Stateless Address Autoconfiguration
Run Code Online (Sandbox Code Playgroud)

最后,在 中设置 NAT iptables

sudo iptables -A FORWARD -o eth0 -i eth1 -s 192.168.0.0/24 -m conntrack --ctstate NEW -j ACCEPT
sudo iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A POSTROUTING -t nat -j MASQUERADE
sudo iptables-save | sudo tee /etc/iptables.sav
Run Code Online (Sandbox Code Playgroud)

并添加iptables-restore < /etc/iptables.sav上述exit 0/etc/rc.local

这个设置主要是通过阅读这个 howto并盯着手册页来实现的。