Created
August 8, 2021 14:48
-
-
Save michaelowens/e63b2dfa9bbfd01dbe4ae697ec7a11cf to your computer and use it in GitHub Desktop.
Share Wifi (or VPN tunnel) through eth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Share Wifi (or VPN tunnel) through eth | |
ip_address="192.168.2.1" | |
netmask="255.255.255.0" | |
dhcp_range_start="192.168.2.2" | |
dhcp_range_end="192.168.2.255" | |
dhcp_time="12h" | |
dns_server="1.1.1.1" | |
eth="eth0" | |
wlan="tun0" # share the vpn tunnel rather than wlan | |
sudo systemctl start network-online.target &> /dev/null | |
sudo iptables -F | |
sudo iptables -t nat -F | |
sudo iptables -t nat -A POSTROUTING -o $wlan -j MASQUERADE | |
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward" | |
sudo ifconfig $eth down | |
sudo ifconfig $eth up | |
sudo ifconfig $eth $ip_address netmask $netmask | |
# Remove default route created by dhcpcd | |
sudo ip route del 0/0 dev $eth &> /dev/null | |
sudo systemctl stop dnsmasq | |
sudo rm -rf /etc/dnsmasq.d/* &> /dev/null | |
printf "interface=$eth\n\ | |
bind-interfaces\n\ | |
server=$dns_server\n\ | |
domain-needed\n\ | |
bogus-priv\n\ | |
dhcp-range=$dhcp_range_start,$dhcp_range_end,$dhcp_time" > /tmp/custom-dnsmasq.conf | |
sudo cp /tmp/custom-dnsmasq.conf /etc/dnsmasq.d/custom-dnsmasq.conf | |
sudo systemctl start dnsmasq | |
# port forward to leased ip | |
miner_ip=$(awk '{ print $3 }' /var/lib/misc/dnsmasq.leases) | |
sudo iptables -t nat -A PREROUTING -p tcp -d 172.27.232.0/20 --dport 44158 -j DNAT --to-destination $miner_ip:44158 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment