Skip to content

Instantly share code, notes, and snippets.

@jhjguxin
Last active November 9, 2018 18:44
Show Gist options
  • Save jhjguxin/5750212 to your computer and use it in GitHub Desktop.
Save jhjguxin/5750212 to your computer and use it in GitHub Desktop.
make a Virtual Router (soft wifi host ap) on Ubuntu 13.04 Ubuntu 15

make a Virtual Router on Ubuntu 13.04

Run this in a terminal:

sudo apt-get install hostapd

Then, open a text editor program, for example gedit. Copy the following into it.

interface=wlan0
driver=nl80211
ssid=francis-ubuntu
channel=1
hw_mode=g
auth_algs=1
wpa=3 
wpa_passphrase=aaabbbccc
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Don't forget to fill in the name of your network after ssid= as well as the password after wpa_passphrase=.

After all these, save the file as hostapd.conf in your home folder.

Now, in your terminal:

sudo hostapd hostapd.conf

Turn the Wi-Fi connection on in your devices and enjoy the fast network share!

you might also want to add dhcpd to assign address to your Android device. Alternatively you can configure iptables to use NAT

install your dhcp server

sudo apt-get install isc-dhcp-server //dhcp服务器,网上有许多是用网桥实现,但我觉得用这个dhcp服务器更简单

安装完以后,在/etc/dhcp/目录下建立文件dhcpd.conf,内容如下:

authoritative;

subnet 192.168.1.0 netmask 255.255.255.0 {
        ## dhcp start  and end IP range ##
        range 192.168.1.100 192.168.1.200;
        option subnet-mask 255.255.255.0;     ## subnet
        option domain-name-servers 8.8.8.8,8.8.4.4; 
        option broadcast-address 192.168.1.255; ## broadcast
        option routers 192.168.1.254; ## router IP
}
 

Save and close the file. To check the syntax of dhcpd.conf file for errors, run:

# dhcpd -t

OR # dhcpd -t /etc/dhcp/dhcpd.conf

How do I start / stop / restart the DHCP server?

Type the following commands:

service isc-dhcp-server start
service isc-dhcp-server stop
service isc-dhcp-server restart
service isc-dhcp-server status

How do I verify that DHCP server UDP port # 67 is opened by dhcpd?

Type any one of the following command

# netstat -tulpn | grep --color "dhcp"

OR

# ps aux | grep --color "[d]hcpd"

OR

# pgrep dhcpd

写一个脚本softAP.sh。内容如下

#/bin/bash!
# https://bugs.launchpad.net/ubuntu/+source/wpa/+bug/1289047
# Temporary solution for hostapd not work with 14.04
sudo nmcli nm wifi off
sudo rfkill unblock wlan
sudo killall hostapd
sudo ifconfig wlan0 192.168.1.254 netmask 255.255.255.0
sudo hostapd /etc/hostapd/hostapd.conf -B
sudo start isc-dhcp-server
sudo iptables -A FORWARD -i wlan0 -o eth0 -s 192.168.1.0/24 -m state --state NEW -j ACCEPT
# sudo iptables -A INPUT -s 192.168.1.0/255.255.255.0 -j ACCEPT # using a subnet mask
sudo iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo bash -c 'echo 1 > /proc/sys/net/ipv4/ip_forward'

run

sudo sh softAP.sh

other

http://unix.stackexchange.com/questions/58461/isc-dhcp-server-fails-to-start-at-boot

dmesg | grep isc-dhcp-server

[   15.267804] init: isc-dhcp-server main process (1201) terminated with status 1
[   15.267839] init: isc-dhcp-server main process ended, respawning

tips

reset iptable

#list all rules
sudo iptable -L
sudo iptable -F

ip_forward 为何老自动改成 0

/proc 是系统动态生成的, 关机就没有了。 如果需要一直启用编辑 /etc/sysctl.conf

$ vi /etc/sysctl.conf

up wlan

iwconfig
sudo /sbin/ifconfig wlan0 up
#/bin/bash!
# sudo apt install dnsmasq hostapd 
# git clone https://github.com/oblique/create_ap.git && cd create_ap
# sudo make install
iwconfig

sudo create_ap wlp3s0 enp4s0f0 francis-ubuntu aaabbbccc123
@felexkemboi
Copy link

How can i create it?

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