Skip to content

Instantly share code, notes, and snippets.

@tao12345666333
Created March 30, 2014 10:13
Show Gist options
  • Save tao12345666333/9870587 to your computer and use it in GitHub Desktop.
Save tao12345666333/9870587 to your computer and use it in GitHub Desktop.
fedora 18 建立wifi热点
$  sudo yum install hostapd
建立hostapd 配置文件
$ cat /etc/hostapd/hostapd.conf
##----------hostapd.conf----------##
interface=wlan0
driver=nl80211
hw_mode=g
channel=10
macaddr_acl=0
auth_algs=3
wpa=2
ssid=myAP
wpa_passphrase=PassWord
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP
rsn_pairwise=TKIP CCMP
##----------hostapd.conf----------##
$ sudo yum install dhcp
建立dhcpd配置文件
$ cat /etc/dhcp/dhcpd.conf
##-------- dhcpd.conf --------##
#dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
default-lease-time 600;
max-lease-time 7200;
subnet 192.168.0.0 netmask 255.255.255.0
{
range 192.168.0.2 192.168.0.10;
option broadcast-address 192.168.0.255;
option routers 192.168.0.1;
option domain-name-servers 192.168.0.1;
}
##-------- dhcpd.conf --------##
开启hostapd
$ sudo hostapd /etc/hostapd/hostapd.conf
开启dhcpd
$ sudo dhcpd
设置ip转发(nat)
$ sudo iptables -t nat -A POSTROUTING -o p3p1 -s 192.168.0.0/24 -j MASQUERADE
$ sudo echo 1 > /proc/sys/net/ipv4/ip_forward
$ iptables -A OUTPUT -p tcp --dport 53 -j ACCEPT
$ iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
*****************************************************
(wlan0是无线网卡 p3p1是以太网卡 用ifconfig 可以查看网卡信息)
以下是我的/etc/rc.d/rc.local
#!/bin/sh
#清除iptables设置
iptables -F
iptables -X
iptables -Z
iptables -t nat -F
#初始化iptables
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
#接受子网段数据包
iptables -A INPUT -i wlan0 -s 192.168.0.0/24 -j ACCEPT
#接受回环数据包
iptables -A INPUT -i lo -j ACCEPT
#接受已建立连接的数据包
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#开启内核转发
echo "1" > /proc/sys/net/ipv4/ip_forward
#开启nat
iptables -t nat -A POSTROUTING -o p3p1 -s 192.168.0.0/24 -j MASQUERADE
#设置网卡地址
ifconfig wlan0 192.168.0.1
#设置dhcp
dhcpd
############################################################
dhcpd可以不用设置的 只要手机设置成静态ip就可以了
@tao12345666333
Copy link
Author

in F19
$ sudo hostapd /etc/hostapd/hostapd.conf
Configuration file: /etc/hostapd/hostapd.conf
nl80211: Failed to set interface wlp3s0 into AP modenl80211 driver
initialization failed.

=================solusion===============
$ ps -A | grep Network
462 ? 00:00:01 NetworkManager
$ sudo kill 462

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment