Internet Connection Sharing: Difference between revisions
imported>Onny mNo edit summary |
imported>Onny mNo edit summary |
||
Line 44: | Line 44: | ||
# Start dnsmasq for DHCP | # Start dnsmasq for DHCP | ||
dnsmasq -d -i eth0 - | dnsmasq -d -i eth0 --dhcp-range=10.0.0.2,10.0.0.255,255.255.255.0,24h | ||
</syntaxhighlight> | </syntaxhighlight> | ||
To cleanup the configured interface run following commands | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
ip addr del 10.0.0.1/24 dev eth0 | |||
ip addr del | ip link set down eth0 | ||
ip link set down | iptables -t nat -D POSTROUTING -o wlan0 -j MASQUERADE | ||
iptables -t nat -D POSTROUTING -o | |||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Networking]] | [[Category:Networking]] |
Revision as of 11:35, 17 April 2023
The following example will describe how to share an active internet connection over a WiFi hotspot or alternatively via ethernet.
Usage
Share an existing internet connection of a wired interface eth0
using a wifi hotspot on wlan0
with the access point name MyAccessPoint
.
nix shell nixpkgs#linux-wifi-hotspot
sudo create_ap wlan0 eth0 MyAccessPoint
Configuration
Persistent share an existing internet connection of a wired interface eth0
using a wifi hotspot on wlan0
with the access point name My Wifi Hotspot
. The network is protected with a simple WPA2 pre-shared key 12345678
.
services.create_ap = {
enable = true;
settings = {
INTERNET_IFACE = "eth0";
WIFI_IFACE = "wlan0";
SSID = "My Wifi Hotspot";
PASSPHRASE = "12345678";
};
};
Share an existing internet connection of a wireless interface wlan0
to clients connected on a ethernet device eth0
.
# Setup ethernet device
ip link set up eth0
ip addr add 10.0.0.1/24 dev eth0
# Enable packet forwarding
sysctl net.ipv4.ip_forward=1
# Enable NAT for leaving packets
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
# Start dnsmasq for DHCP
dnsmasq -d -i eth0 --dhcp-range=10.0.0.2,10.0.0.255,255.255.255.0,24h
To cleanup the configured interface run following commands
ip addr del 10.0.0.1/24 dev eth0
ip link set down eth0
iptables -t nat -D POSTROUTING -o wlan0 -j MASQUERADE