linux - Wifi sharing over eth0
2014-07
There are a lot of tutorials how to share network connection with your usb wifi adapter and I tried lots of them but it is still not working. Can you please help me with my problem. Here is my network described:
I have eth0 which is connected to the internet. It is configured for wpa_supplicant 802.1X. It works as it should.
My wifi usb adapter is wlan0 and I had it in managed mode it supports access point mode and I assigned static ip to it. I installed hostapd and run with proper config. It sets up and I am able to connect to the ap, but can't access the internet.
In my iptables I did nat-ing between eth0 and br0. But if I tried to ping some external IP with -I wlan0 it didn't work.
Can you describe what should I do, step by step. I really need to set this up, quick as possible.
Many thanks.
Setting up a hotspot requires several steps, provided your card can do it (to check, see my comment above). The follwoing commands apply to Debian and derivatives, they can easily be adapted to other distros.
sudo apt-get install haveged isc-dhcp-server hostapd
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Edit the file /etc/default/hostapd and replace #DAEMON_CONF="" with
DAEMON_CONF="/etc/hostapd/hostapd.conf"
Edit the file /etc/hostapd/hostapd.conf and put this into it:
ctrl_interface=/var/run/hostapd
driver=nl80211
interface=wlan0
bridge=br0
hw_mode=g
ieee80211n=1
channel=1
ssid=MYWifi
auth_algs=1
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=My_Secret_Password
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
Replace channel number, ssid and wpa_passphrase with something suitable to you.
Edit the file /etc/default/isc-dhcp-server and replace the line INTERFACES="" with
INTERFACES="br0"
Now edit /etc/dhcp/dhcp.conf and put only these lines into it:
subnet 10.168.10.0 netmask 255.255.255.0 {
range 10.168.10.10 10.168.10.200;
option broadcast-address 10.168.10.255;
option routers 10.168.10.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name "my-network";
option domain-name-servers 208.67.222.222, 208.67.220.220;
}
Now:
sudo service hostapd start
sudo ip tuntap add tap0 mode tap
sudo ip link set dev tap0 up
sudo ip link set dev tap0 master br0
sudo ip link set dev br0 down
sudo ip addr add 10.168.10.1/24 dev br0
sudo ip link set dev br0 up
sudo service isc-dhcp-server start
That's it.
You don't need anything special: I set it up on 10.04 NetBook using the normal Network GUI:-
- Bring up Network Connections (right-click panel icon and choose Edit Connections...).
- On Wireless tab, click on Add button.
- The box Editing Wireless connection n will appear (you can change the name to something more appropriate if you wish).
- On its Wireless tab choose whatever SSID name you wish, then set Mode Ad-hoc and select Available to all users.
- Under IPv4 Settings tab choose Method Shared to other computers.
- Under IPv6 Settings I set Method to Ignore; if you use IPv6, you will need another setting (I don't, so I can't advise).
- Finally set the appropriate Security and Key on the Wireless Security tab.
That's it: any device logging on to0 this wireless network will share this host's ethernet connection and the host will provide DHCP
On my CentOS system, Wifi Interface (wlan0) is connected to the internet through an access point. The IPV4 for it is assigned dynamically by the ISP. The eth0 for this machine is manually configured to use 172.172.4.3/16
I have another CentOS box which is connected to the box above through eth0 interface (wired LAN) it is a direct connection without any intermediate devices like switches. The IP is manually configured to 172.172.4.2/16
I want to be able to access the Wifi internet available @172.172.4.3
on the machine 172.172.4.2
. I searched the internet and came across some settings like marking the Wifi as Shared or configuring iptables, but none of them worked.
How do I go about it?
You've painted yourself into a corner. You've setup your network to be bridged, not routed (IPs in same subnet). Yet you have a Wifi client connection, which cannot be bridged to.
The Wifi specification prohibits bridging to an access point client connection. The access point will not allow it. That's why WDS must be configured in both access points. Neither supports bridging to an ordinary client.
It's time to rethink your setup. Here are four possible options:
Add a second access point and configure WDS in both access points. Connect wired machines to the second access point. This assumes your existing access point supports WDS.
Use a client station device. Connect this machine to that station device. That way, no bridging will be needed because each client connection will have only a single machine.
Add a second wireless router that can run aftermarket firmware like Tomato or OpenWRT. These have a feature called "client bridging" that uses a form of NAT to make this work (making more than one system appear to have the same hardware address). You can then connect any number of wired clients to this device. This won't require any changes to your existing access point.
Add a regular wireless interface to this machine and let it make its own client connection to the access point.
Edit
If you want to use NAT, you need to assign each end of the private link between the two machines a private IP address. For example, you can use 192.168.200.1/24 and 192.168.200.2/24. You will also need to make the private address of the machine doing NAT (the one with both connections) the other one's default gateway and you'll need to set its DNS server IPs manually.
Are you aware that the IPs in the range 172.172.0.0/16 are public IPs ?
This might be a problem if you want to route/nat your internet access in your private network.
Try remapping your network to something like 172.24.0.0/16 and then apply allquixotic's solution.
See http://www.revsys.com/writings/quicktips/nat.html
Also, be aware that the "/16" you're specifying is actually an IP address range, not a specific IP. See http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing . If you are trying to assign a specific static IP address to a host and you are specifying /16 at the end, you are doing it wrong. You would only need to use a CIDR if you are specifying the DHCP provisioning range on the host side (the "4.3" box in your case) -- the DHCP server would then choose from that IP range to hand out to clients.