home       inleiding       sysadmin       services       links       bash       werk       nothing      

iptables 2023 met NAT

iptables-setup1-2023

teacher@vbox01:~$ cat /etc/iptables/iptables.003.sh

#! /bin/bash
#
#  iptables-script 
#  bvdb  ( 25/04/2023 ) version 003 with NAT ROUTING
######################################################
#
#  here follows the script ....
# v = verbose, X = flush tables, F = delete non standard chains

# general
iptables -vX
iptables -vF

# nat and masquerading -t refers to table
iptables -vt nat -F
iptables -vt nat -X

# mangling TCP header
iptables -vt mangle -F
iptables -vt mangle -X

# reset policies -P refers to policies
iptables -vP INPUT ACCEPT
iptables -vP OUTPUT ACCEPT
iptables -vP FORWARD ACCEPT

# turn off routing
echo 0 > /proc/sys/net/ipv4/ip_forward

### HERE COMES THE IPTABLES LOGIC (one day, who knows when ?)
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -vt nat -A POSTROUTING -o enp0s3 -j SNAT --to 10.104.111.111

### PRINT iptables configuration
###
#
echo ">>>>> iptables -n -L"
iptables -n -L
echo "--------------"
echo ">>>>> iptables -S"
iptables -S
echo "--------------"
echo ">>>>> iptables -t nat -L"
iptables -t nat -L
echo "--------------"
echo ">>>>> iptables -t mangle -L"
iptables -t mangle -L
echo "--------------"
echo "routing set: " `cat /proc/sys/net/ipv4/ip_forward`
echo "=============="