update internet sharing post
This commit is contained in:
parent
bc971c97c4
commit
49f9bd82fa
@ -9,6 +9,8 @@ categories:
|
|||||||
- ipv6 router advertisement
|
- ipv6 router advertisement
|
||||||
---
|
---
|
||||||
|
|
||||||
|
**Update:** Added adhoc wlan network
|
||||||
|
|
||||||
A guide to connect with a different machine using a ethernet cable for
|
A guide to connect with a different machine using a ethernet cable for
|
||||||
internet sharing or just transferring files:
|
internet sharing or just transferring files:
|
||||||
|
|
||||||
@ -17,11 +19,12 @@ internet sharing or just transferring files:
|
|||||||
$ pacman -S dnsmasq iproute2
|
$ pacman -S dnsmasq iproute2
|
||||||
|
|
||||||
2. Copy over the configuration files at the end of the article and edit the
|
2. Copy over the configuration files at the end of the article and edit the
|
||||||
*/etc/conf.d/share-internet* to match your network setup.
|
*/etc/conf.d/share-internet@\<device\>* to match your network setup. (where
|
||||||
|
\<device\> is your network device)
|
||||||
|
|
||||||
3. Start the sharing service with systemd
|
3. Start the sharing service with systemd
|
||||||
|
|
||||||
$ sudo systemctl start internet-sharing.service
|
$ sudo systemctl start internet-sharing@<device>.service
|
||||||
|
|
||||||
After that the other machine can connect via dhcp. It will get an ipv4
|
After that the other machine can connect via dhcp. It will get an ipv4
|
||||||
address from the **10.20.0.0/24** subnet and a ipv6 address from the **fd21:30c2:dd2f::**
|
address from the **10.20.0.0/24** subnet and a ipv6 address from the **fd21:30c2:dd2f::**
|
||||||
@ -34,10 +37,26 @@ network with the device on which the dhcp service is running.
|
|||||||
|
|
||||||
Happy networking!
|
Happy networking!
|
||||||
|
|
||||||
{% include_code /etc/conf.d/share-internet lang:bash share-internet/share-internet %}
|
|
||||||
|
|
||||||
{% include_code /etc/systemd/system/share-internet.service lang:ini share-internet/share-internet.service %}
|
{% include_code /etc/systemd/system/share-internet.service lang:ini share-internet/share-internet.service %}
|
||||||
|
|
||||||
{% include_code /etc/dnsmasq.conf lang:ini share-internet/dnsmasq.conf %}
|
{% include_code /etc/dnsmasq.conf lang:ini share-internet/dnsmasq.conf %}
|
||||||
|
|
||||||
{% include_code /etc/dnsmasq.conf.dhcp lang:bash share-internet/dnsmasq.conf.dhcp %}
|
{% include_code /etc/dnsmasq.conf.dhcp lang:bash share-internet/dnsmasq.conf.dhcp %}
|
||||||
|
|
||||||
|
Ethernet to Wlan:
|
||||||
|
|
||||||
|
{% include_code /etc/conf.d/share-internet@enp0s25 lang:bash share-internet/share-internet@enp0s25 %}
|
||||||
|
|
||||||
|
Wlan to Ethernet:
|
||||||
|
|
||||||
|
If you have luck and your wifi driver is capable of the infrastructure mode,
|
||||||
|
you should take a look at hostadp, in my case I have to create an adhoc network.
|
||||||
|
To enable the adhoc network:
|
||||||
|
|
||||||
|
$ sudo systemctl enable wireless-adhoc@\<device\>.service
|
||||||
|
|
||||||
|
{% include_code /etc/conf.d/share-internet@wlp3s0 lang:bash share-internet/share-internet@wlp3s0 %}
|
||||||
|
|
||||||
|
{% include_code /etc/systemd/system/wireless-adhoc@.service lang:ini share-internet/wireless-adhoc@.service %}
|
||||||
|
|
||||||
|
{% include_code /etc/wpa_supplicant/wpa_supplicant-adhoc-wlp3s0.conf lang:bash share-internet/wpa_supplicant-adhoc-wlp3s0.conf %}
|
||||||
|
@ -3,5 +3,3 @@ server=8.8.8.8
|
|||||||
server=8.8.4.4
|
server=8.8.4.4
|
||||||
no-resolv
|
no-resolv
|
||||||
cache-size=2000
|
cache-size=2000
|
||||||
|
|
||||||
#conf-file=/etc/dnsmasq.conf.dhcp
|
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
# no need to modify
|
|
||||||
# ingoing and outgoing device will be set by the systemd service
|
|
||||||
interface=enp0s25
|
|
||||||
no-dhcp-interface=wlp3s0
|
|
||||||
dhcp-range=10.20.0.100,10.20.0.199,infinite
|
|
||||||
dhcp-option=3,10.20.0.1 # router
|
|
||||||
dhcp-option=5,10.20.0.1 # dns
|
|
||||||
dhcp-option=42,10.20.0.1 # ntp
|
|
||||||
dhcp-range=fd21:30c2:dd2f::,ra-stateless,ra-names,infinite
|
|
||||||
enable-ra
|
|
@ -1,4 +0,0 @@
|
|||||||
# Network device where other hosts are connect to, ex: eth0
|
|
||||||
INTERNAL_DEVICE="enp0s25"
|
|
||||||
# Device which has internet access, ex: wlan0 or usb0
|
|
||||||
EXTERNAL_DEVICE="wlp3s0"
|
|
@ -1,27 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description='share internet'
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=oneshot
|
|
||||||
EnvironmentFile=/etc/conf.d/share-internet
|
|
||||||
RemainAfterExit=yes
|
|
||||||
ExecStart=/usr/bin/sed -ie 's!^#conf-file=/etc/dnsmasq\.conf\.dhcp!conf-file=/etc/dnsmasq.conf.dhcp!' /etc/dnsmasq.conf
|
|
||||||
ExecStart=/usr/bin/sed -ie 's/^interface=[[:alnum:]]+/interface=$INTERNAL_DEVICE/' /etc/dnsmasq.conf.dhcp
|
|
||||||
ExecStart=/usr/bin/sed -ie 's/^no-dhcp-interface=[[:alnum:]]+/no-dhcp-interface=$EXTERNAL_DEVICE/' /etc/dnsmasq.conf.dhcp
|
|
||||||
ExecStart=/usr/bin/iptables -t nat -A POSTROUTING -o $EXTERNAL_DEVICE -j MASQUERADE
|
|
||||||
ExecStart=/usr/bin/ip6tables -t nat -A POSTROUTING -o $EXTERNAL_DEVICE -j MASQUERADE
|
|
||||||
ExecStart=/usr/bin/sysctl -w net.ipv4.ip_forward=1 net.ipv6.conf.all.forwarding=1
|
|
||||||
ExecStart=/usr/bin/ip addr add 10.20.0.1/24 dev $INTERNAL_DEVICE
|
|
||||||
ExecStart=/usr/bin/ip addr add fd21:30c2:dd2f::1/64 dev $INTERNAL_DEVICE
|
|
||||||
ExecStart=/usr/bin/systemctl restart dnsmasq
|
|
||||||
|
|
||||||
ExecStop=/usr/bin/ip addr del 10.20.0.1/24 dev $INTERNAL_DEVICE
|
|
||||||
ExecStop=/usr/bin/ip addr del fd21:30c2:dd2f::1/64 dev $INTERNAL_DEVICE
|
|
||||||
ExecStop=/usr/bin/sysctl -w net.ipv4.ip_forward=0 net.ipv6.conf.all.forwarding=0
|
|
||||||
ExecStop=/usr/bin/iptables -t nat -D POSTROUTING -o $EXTERNAL_DEVICE -i $INTERNAL_DEVICE -j MASQUERADE
|
|
||||||
ExecStop=/usr/bin/ip6tables -t nat -D POSTROUTING -o $EXTERNAL_DEVICE -i $INTERNAL_DEVICE -j MASQUERADE
|
|
||||||
ExecStop=/usr/bin/sed -ie 's!^conf-file=/etc/dnsmasq\.conf\.dhcp!#conf-file=/etc/dnsmasq.conf.dhcp!' /etc/dnsmasq.conf
|
|
||||||
ExecStop=/usr/bin/systemctl restart dnsmasq
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
35
source/downloads/code/share-internet/share-internet@.service
Normal file
35
source/downloads/code/share-internet/share-internet@.service
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
[Unit]
|
||||||
|
Description='share internet'
|
||||||
|
Conflicts=dnsmasq.service
|
||||||
|
Wants=network.target
|
||||||
|
Before=network.target
|
||||||
|
BindsTo=sys-subsystem-net-devices-%i.device
|
||||||
|
After=sys-subsystem-net-devices-%i.device
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
EnvironmentFile=/etc/conf.d/share-internet@%i
|
||||||
|
ExecStartPre=/usr/bin/dnsmasq --test
|
||||||
|
ExecStartPre=/usr/bin/iptables -t nat -A POSTROUTING -o $EXTERNAL_DEVICE -j MASQUERADE
|
||||||
|
ExecStartPre=/usr/bin/ip6tables -t nat -A POSTROUTING -o $EXTERNAL_DEVICE -j MASQUERADE
|
||||||
|
ExecStartPre=/usr/bin/sysctl -w net.ipv4.ip_forward=1 net.ipv6.conf.all.forwarding=1
|
||||||
|
ExecStartPre=/usr/bin/ip link set %i up
|
||||||
|
ExecStartPre=/usr/bin/ip addr add ${IP4_ADDRESS}/${IP4_NETMASK} dev %i
|
||||||
|
ExecStartPre=/usr/bin/ip addr add ${IP6_ADDRESS}/${IP4_NETMASK} dev %i
|
||||||
|
|
||||||
|
ExecStart=/usr/bin/dnsmasq -k --user=dnsmasq --pid-file \
|
||||||
|
--conf-file=/etc/dnsmasq.conf \
|
||||||
|
--interface=%i \
|
||||||
|
--dhcp-range=${IP4_SUBNET},infinite \
|
||||||
|
--dhcp-range=${IP6_SUBNET},ra-stateless,ra-names,infinite \
|
||||||
|
--dhcp-option=3,${IP4_ADDRESS} \
|
||||||
|
--dhcp-option=5,${IP4_ADDRESS} \
|
||||||
|
--enable-ra \
|
||||||
|
--no-daemon
|
||||||
|
ExecReload=/bin/kill -HUP $MAINPID
|
||||||
|
|
||||||
|
ExecStopPost=/usr/bin/ip addr flush dev %i
|
||||||
|
ExecStopPost=/usr/bin/ip link set %i down
|
||||||
|
ExecStopPost=/usr/bin/sysctl -w net.ipv4.ip_forward=0 net.ipv6.conf.all.forwarding=0
|
||||||
|
ExecStopPost=/usr/bin/iptables -t nat -D POSTROUTING -o $EXTERNAL_DEVICE -j MASQUERADE
|
||||||
|
ExecStopPost=/usr/bin/ip6tables -t nat -D POSTROUTING -o $EXTERNAL_DEVICE -j MASQUERADE
|
10
source/downloads/code/share-internet/share-internet@enp0s25
Normal file
10
source/downloads/code/share-internet/share-internet@enp0s25
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# Device which has internet access, ex: wlan0 or usb0
|
||||||
|
EXTERNAL_DEVICE="wlp3s0"
|
||||||
|
|
||||||
|
IP4_ADDRESS="10.20.0.1"
|
||||||
|
IP4_NETMASK="24"
|
||||||
|
IP4_SUBNET="10.20.0.2,10.20.0.255"
|
||||||
|
|
||||||
|
IP6_ADDRESS="fd21:30c2:dd2f::1"
|
||||||
|
IP6_NETMASK="64"
|
||||||
|
IP6_SUBNET="fd21:30c2:dd2f::"
|
10
source/downloads/code/share-internet/share-internet@wlp3s0
Normal file
10
source/downloads/code/share-internet/share-internet@wlp3s0
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# Device which has internet access, ex: wlan0 or usb0
|
||||||
|
EXTERNAL_DEVICE="enp0s20u2"
|
||||||
|
|
||||||
|
IP4_ADDRESS="10.20.0.1"
|
||||||
|
IP4_NETMASK="24"
|
||||||
|
IP4_SUBNET="10.20.0.100,10.20.0.199"
|
||||||
|
|
||||||
|
IP6_ADDRESS="fd21:30c2:dd2f::1"
|
||||||
|
IP6_NETMASK="64"
|
||||||
|
IP6_SUBNET="fd21:30c2:dd2f::"
|
15
source/downloads/code/share-internet/wireless-adhoc@.service
Normal file
15
source/downloads/code/share-internet/wireless-adhoc@.service
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Ad-hoc wireless network connectivity (%i)
|
||||||
|
Wants=network.target
|
||||||
|
Before=network.target
|
||||||
|
Conflicts=netctl-auto@.service
|
||||||
|
BindsTo=sys-subsystem-net-devices-%i.device
|
||||||
|
After=sys-subsystem-net-devices-%i.device
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStartPre=/usr/bin/rfkill unblock wifi
|
||||||
|
ExecStart=/usr/sbin//wpa_supplicant -D nl80211,wext -c/etc/wpa_supplicant/wpa_supplicant-adhoc-%I.conf -i%I
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
RequiredBy=share-internet@%i.service
|
@ -0,0 +1,29 @@
|
|||||||
|
ctrl_interface=DIR=/run/wpa_supplicant GROUP=wheel
|
||||||
|
|
||||||
|
# use 'ap_scan=2' on all devices connected to the network
|
||||||
|
ap_scan=2
|
||||||
|
|
||||||
|
network={
|
||||||
|
ssid="The.Secure.Network"
|
||||||
|
mode=1
|
||||||
|
frequency=2432
|
||||||
|
proto=WPA
|
||||||
|
key_mgmt=WPA-NONE
|
||||||
|
pairwise=NONE
|
||||||
|
group=TKIP
|
||||||
|
psk="fnord"
|
||||||
|
}
|
||||||
|
|
||||||
|
# MacOS X and Networmanager aren't capable of using WPA/WPA2 for Adhoc Networks
|
||||||
|
#network={
|
||||||
|
# ssid="The.Insecure.Network"
|
||||||
|
# mode=1
|
||||||
|
# frequency=2432
|
||||||
|
# proto=WPA
|
||||||
|
# key_mgmt=NONE
|
||||||
|
# pairwise=NONE
|
||||||
|
# group=TKIP
|
||||||
|
#
|
||||||
|
# wep_key0="fnord"
|
||||||
|
# wep_tx_keyidx=0
|
||||||
|
#}
|
Loading…
Reference in New Issue
Block a user