Difference between revisions of "Debian as router"

From RHS Wiki
Jump to navigation Jump to search
Line 23: Line 23:
  
 
* If you want to delete the rule: 3    16409 1098K MASQUERADE  all  --  *      tun0    15.17.165.42        0.0.0.0/0
 
* If you want to delete the rule: 3    16409 1098K MASQUERADE  all  --  *      tun0    15.17.165.42        0.0.0.0/0
  iptables -t nat -D POSTROUTING 3
+
  sudo iptables -t nat -D POSTROUTING 3

Revision as of 10:58, 10 October 2018

Make a debian box router

Enable routing

Temporal

sudo sysctl -w net.ipv4.ip_forward=1 # 

Permanent

sudo nano /etc/sysctl.conf
   net.ipv4.ip_forward = 1

Create NAT rule at IPTABLES

sudo iptables -t nat -A POSTROUTING -s 15.17.170.215/32 -o tun0 -j MASQUERADE

List iptables NAT rules

sudo iptables -t nat -L -n -v 

Delete NAT rule

  • List the rules with line numbers
sudo iptables -t nat -v -L POSTROUTING -n --line-number
Chain POSTROUTING (policy ACCEPT 241 packets, 23342 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1        2   168 MASQUERADE  all  --  *      tun0    15.17.170.215        0.0.0.0/0           
2      250 15024 MASQUERADE  all  --  *      tun0    15.17.164.7          0.0.0.0/0           
3    16409 1098K MASQUERADE  all  --  *      tun0    15.17.165.42         0.0.0.0/0
  • If you want to delete the rule: 3 16409 1098K MASQUERADE all -- * tun0 15.17.165.42 0.0.0.0/0
sudo iptables -t nat -D POSTROUTING 3