From 49f9bd82fa1f1eb1505c2a752be018a289cbffbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sun, 9 Feb 2014 09:59:11 +0100 Subject: [PATCH] update internet sharing post --- ...d-ipv6-on-archlinux-using-dnsmasq.markdown | 27 +++++++++++--- .../code/share-internet/dnsmasq.conf | 2 -- .../code/share-internet/dnsmasq.conf.dhcp | 10 ------ .../code/share-internet/share-internet | 4 --- .../share-internet/share-internet.service | 27 -------------- .../share-internet/share-internet@.service | 35 +++++++++++++++++++ .../share-internet/share-internet@enp0s25 | 10 ++++++ .../code/share-internet/share-internet@wlp3s0 | 10 ++++++ .../share-internet/wireless-adhoc@.service | 15 ++++++++ .../wpa_supplicant-adhoc-wlp3s0.conf | 29 +++++++++++++++ 10 files changed, 122 insertions(+), 47 deletions(-) delete mode 100644 source/downloads/code/share-internet/dnsmasq.conf.dhcp delete mode 100644 source/downloads/code/share-internet/share-internet delete mode 100644 source/downloads/code/share-internet/share-internet.service create mode 100644 source/downloads/code/share-internet/share-internet@.service create mode 100644 source/downloads/code/share-internet/share-internet@enp0s25 create mode 100644 source/downloads/code/share-internet/share-internet@wlp3s0 create mode 100644 source/downloads/code/share-internet/wireless-adhoc@.service create mode 100644 source/downloads/code/share-internet/wpa_supplicant-adhoc-wlp3s0.conf diff --git a/source/_posts/2014-02-08-internet-sharing-ipv4-and-ipv6-on-archlinux-using-dnsmasq.markdown b/source/_posts/2014-02-08-internet-sharing-ipv4-and-ipv6-on-archlinux-using-dnsmasq.markdown index 24d0a31..423d196 100644 --- a/source/_posts/2014-02-08-internet-sharing-ipv4-and-ipv6-on-archlinux-using-dnsmasq.markdown +++ b/source/_posts/2014-02-08-internet-sharing-ipv4-and-ipv6-on-archlinux-using-dnsmasq.markdown @@ -9,6 +9,8 @@ categories: - ipv6 router advertisement --- +**Update:** Added adhoc wlan network + A guide to connect with a different machine using a ethernet cable for internet sharing or just transferring files: @@ -17,11 +19,12 @@ internet sharing or just transferring files: $ pacman -S dnsmasq iproute2 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@\* to match your network setup. (where + \ is your network device) 3. Start the sharing service with systemd - $ sudo systemctl start internet-sharing.service + $ sudo systemctl start internet-sharing@.service 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::** @@ -34,10 +37,26 @@ network with the device on which the dhcp service is running. 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/dnsmasq.conf lang:ini share-internet/dnsmasq.conf %} {% 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@\.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 %} diff --git a/source/downloads/code/share-internet/dnsmasq.conf b/source/downloads/code/share-internet/dnsmasq.conf index 5a01156..c931702 100644 --- a/source/downloads/code/share-internet/dnsmasq.conf +++ b/source/downloads/code/share-internet/dnsmasq.conf @@ -3,5 +3,3 @@ server=8.8.8.8 server=8.8.4.4 no-resolv cache-size=2000 - -#conf-file=/etc/dnsmasq.conf.dhcp diff --git a/source/downloads/code/share-internet/dnsmasq.conf.dhcp b/source/downloads/code/share-internet/dnsmasq.conf.dhcp deleted file mode 100644 index 5f3d7c4..0000000 --- a/source/downloads/code/share-internet/dnsmasq.conf.dhcp +++ /dev/null @@ -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 diff --git a/source/downloads/code/share-internet/share-internet b/source/downloads/code/share-internet/share-internet deleted file mode 100644 index 755cb48..0000000 --- a/source/downloads/code/share-internet/share-internet +++ /dev/null @@ -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" diff --git a/source/downloads/code/share-internet/share-internet.service b/source/downloads/code/share-internet/share-internet.service deleted file mode 100644 index 3d78b3a..0000000 --- a/source/downloads/code/share-internet/share-internet.service +++ /dev/null @@ -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 diff --git a/source/downloads/code/share-internet/share-internet@.service b/source/downloads/code/share-internet/share-internet@.service new file mode 100644 index 0000000..3f527bd --- /dev/null +++ b/source/downloads/code/share-internet/share-internet@.service @@ -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 diff --git a/source/downloads/code/share-internet/share-internet@enp0s25 b/source/downloads/code/share-internet/share-internet@enp0s25 new file mode 100644 index 0000000..04cc719 --- /dev/null +++ b/source/downloads/code/share-internet/share-internet@enp0s25 @@ -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::" diff --git a/source/downloads/code/share-internet/share-internet@wlp3s0 b/source/downloads/code/share-internet/share-internet@wlp3s0 new file mode 100644 index 0000000..9d0ce89 --- /dev/null +++ b/source/downloads/code/share-internet/share-internet@wlp3s0 @@ -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::" diff --git a/source/downloads/code/share-internet/wireless-adhoc@.service b/source/downloads/code/share-internet/wireless-adhoc@.service new file mode 100644 index 0000000..4755841 --- /dev/null +++ b/source/downloads/code/share-internet/wireless-adhoc@.service @@ -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 diff --git a/source/downloads/code/share-internet/wpa_supplicant-adhoc-wlp3s0.conf b/source/downloads/code/share-internet/wpa_supplicant-adhoc-wlp3s0.conf new file mode 100644 index 0000000..7aebd98 --- /dev/null +++ b/source/downloads/code/share-internet/wpa_supplicant-adhoc-wlp3s0.conf @@ -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 +#}