【Ubuntu】单无线网卡创建无线热点共享网络连接

来源:互联网 发布:阿里云域名 跳转 编辑:程序博客网 时间:2024/05/17 02:39

主要工具:

  1. iw : A new nl80211 based CLI configuration utility for wireless
    devices.
  2. hostapd : A user space software access point capable of
    turning normal network interface cards into access points and
    authentication servers.
  3. iptables : Used to set up, maintain, and inspect the tables of IPv4 packet filter rules in the Linux kernel.
  4. udhcpd : A very small DHCP server program geared towards embedded systems.
  5. udpcpc : A very small DHCP client program geared towards embedded systems.
  6. macchanger : A GNU/Linux utility for viewing/manipulating the MAC address of network interfaces.

安装方法:

sudo apt-get install iw hostapd iptables udhcpd udhcpc macchanger

各工具配置文件:

/etc/hostapd.conf

interface=new1driver=nl80211ssid=xxxxxxxxxchannel=11                #I sugest you to use the same channel as your wireless networkhw_mode=gwme_enabled=1macaddr_acl=0auth_algs=1ignore_broadcast_ssid=0wpa=3wpa_passphrase=xxxxpasswordxxxxxwpa_key_mgmt=WPA-PSKwpa_pairwise=TKIPrsn_pairwise=CCMP

/etc/udhcpd.conf

start 192.168.0.102         #These IPs must to be in the same subset as your current default routeend 192.168.0.117 interface new1 opt dns 114.114.114.114 option subnet 255.255.255.0opt router 192.168.0.101    #This IP must to be in the same subset as your current default routeoption  domain  localhost

/etc/default/udhcpd

# Comment the following line to enable#DHCPD_ENABLED="no"# Options to pass to busybox' udhcpd.## -S    Log to syslog# -f    run in foregroundDHCPD_OPTS="-S"

/etc/wpa_supplicant.conf

ctrl_interface=/run/wpa_supplicantnetwork={    ssid="CMCC-EDU"    key_mgmt=NONE}

启动 & 关闭 热点 脚本:

启动热点 脚本:

#!/bin/bashservice network-manager stopsleep 1pkill -15 nm-appletsleep 1ifconfig wlan0 down             #wlan0 - the name of your wireless adaptersleep 1iw phy phy0 interface add new0 type stationiw phy phy0 interface add new1 type __apsleep 2macchanger --mac 00:11:22:33:44:55 new0macchanger --mac 00:11:22:33:44:66 new1ifconfig new1 192.168.0.101 up  #192.168.0.101 - the same IP defined for router in 'udhcpd.conf' file hostapd /etc/hostapd.conf &sleep 2service udhcpd startwpa_supplicant -i new0 -c /etc/wpa_supplicant.conf &sleep 10udhcpc -i new0echo "1" > /proc/sys/net/ipv4/ip_forwardiptables --table nat --append POSTROUTING --out-interface new0 -j MASQUERADEiptables --append FORWARD --in-interface new1 -j ACCEPT

关闭热点 脚本:

#!/bin/bashkillall wpa_supplicantkillall hostapdservice udhcpd stopiw dev new0 deliw dev new1 delifconfig wlan0 uproute add -net 0.0.0.0/0 netmask 0.0.0.0 dev wlan0iptables --table nat --delete POSTROUTING --out-interface new0 -j MASQUERADEiptables --delete FORWARD --in-interface new1 -j ACCEPTservice network-manager startnm-applet &

其他备选方法:

create_ap 脚本。
注意!此脚本在单无线网卡上开热点时会失败。

Ref:
1. http://askubuntu.com/questions/318973/how-do-i-create-a-wifi-hotspot-sharing-wireless-internet-connection-single-adap
2. https://wireless.wiki.kernel.org/en/users/documentation/iw
3. https://wiki.gentoo.org/wiki/Hostapd
4. https://w1.fi/cgit/hostap/plain/hostapd/hostapd.conf
5. https://github.com/oblique/create_ap

0 0
原创粉丝点击