正常咱们的无线网卡工做在sta模式,经过链接路由进行上网。在Windows下,咱们能够用猎豹、360和腾讯管家里的一些软件助手,把咱们的无线网卡开一个热点,一样,在Linux中。咱们也能够把咱们无线网卡的热点打开,让其余设备可以链接。vim
基本配置
首先确保Linux能识别到无线网卡
ifconfig 能看到 wlan0 而且有路由分配的ip
把原来的动态IP改成静态IP
bash
sudo vim /etc/network/interface auto lo iface lo inet loopback auto wlan0 iface wlan0 inet static wpa-ssid "路由名" wpa-psk "密码" address **.**.**.**就写上面的ifconfig的吧 netmask 255.255.255.0 gateway 192.168.0.1
重启网络 sudo /etc/init.d/networking restart
重启网卡 sudo ifup wlan0
markdown
安装hostapd服务
hostapd就是用来打开无线网卡的AP模式的网络
sudo apt-get install hostapd sudo vim /etc/default/hostapd 修改 #DAEMON_CONF=""为 DAEMON_CONF="/etc/hostapd/hostapd.conf" sudo vim /etc/hostapd/hostapd.conf #网卡 interface=wlan0 #驱动 driver=* #WiFi名 ssdi=wifi-name #工做模式 802.11n hw_mode=n #信道 channel=* #WPA2配置 wpa=2 #WiFi密码 wpa_passphrase=wifi-passwd #认证方式 WPA-PSK wpa_key_mgmt=WPA-PSK #加密方式 wpa_pairwise=CCMP rsn_pairwise=CCMP beacon_int=100 auth_algs=3 wmm_enabled=1
sudo service hostapd restart 重启hostapd服务dom
安装配置 isc-dhcp-server服务
hostapd仅仅开启了无线网卡的AP模式,可是设备链接时,该如何分配IP呢,这就须要借助isc-dhcp-server来动态分配IPoop
sudo apt-get install isc-dhcp-server sudo vim /etc/dhcp/dhcpd.conf default-lease-time 600; max-lease-time 7200; log-facility local7; //网关IP 就是无线网卡的static ip subnet 192.168.**.** netmask 255.255.255.0{ range 192.168.0.1 192.168.0.120; option routers 192.168.**.**; option broadcast-address 192.168.0.105; option domain-name-servers 8.8.8.8,8.8.4.4; default-lease-time 600; max-lease-time 7200; } sudo service isc-dhcp-server restart //重启服务
配置路由转发规则
上面两步仅仅保证了,AP服务,你能够链接、有了dhcp你能够得到动态IP,可是如何保证设备能经过这个无线网卡来上网呢,这须要配置,将无线网卡wlan0的设备传输数据转发到有线网卡eth0上面。因此须要配置一下路由转发规则,打通数据传输的链路。atom
使用iptables实现简答的转发加密
sudo iptables -F sudo iptables -X sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE sudo bash iptables-save > /etc/iptables.up.rules exit sudo /etc/init.d/iptables start sudo echo 1> /proc/sys/net/ipv4/ip——forward 开启路由转发