Linux share internet (lan/wan/wifi/vpn)

Date: 2018-07-21
#!/bin/bash
addr=10.0.0.1
net=10.0.0.0
mask=255.255.255.0
lan=enp4s0f1
wan=wlp3s0

ip addr replace $addr dev $lan
route del -net $net netmask $mask dev $lan
route add -net $net netmask $mask dev $lan
sysctl net.ipv4.ip_forward=1
iptables -t nat -A POSTROUTING -o $wan -j MASQUERADE
iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i $lan -o $wan -j ACCEPT
#!/bin/bash
gw=10.0.0.1
addr=10.0.0.2
net=10.0.0.0
mask=255.255.255.0
lan=enp2s0
# with routes:
ip addr replace $addr dev $lan
route del -net $net netmask $mask dev $lan
route add -net $net netmask $mask dev $lan
route del default gw $gw dev $lan
route add default gw $gw dev $lan
#!/bin/bash
src=tun0
dest=enp7s0
# enable forwarding for VPN sharing                 
sysctl net.ipv4.ip_forward=1
iptables -t nat -A POSTROUTING -o $dest -j MASQUERADE                                                                                                                                               
iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT                                                                                                                           
iptables -A FORWARD -i $src -o $dest -j ACCEPT
11810cookie-checkLinux share internet (lan/wan/wifi/vpn)