shell_script

centos8 firewall nat 세팅 (추가/삭제) 스크립트

sysman 2021. 9. 1. 11:28
#!/bin/bash



firewall-cmd --zone=external --list-all | grep -e toaddr



case $1 in
  1)
  echo "#######################"
  echo "=== Firewall nat add Set ==="
  echo "#######################"
  read -p "Please input export port num: " port
  read -p "Please input proto(tcp/udp): " proto
  read -p "Please input inner toport num: " toport
  read -p "Please input toaddr(private ip addr): " toaddr

  firewall-cmd --permanent --zone=external --add-forward-port=port=$port:proto=$proto:toport=$toport:toaddr=$toaddr
  firewall-cmd --reload
  firewall-cmd --zone=external --list-all | grep -e toaddr
  ;; 

  2)
  echo "#########################"
  echo "=== Firewall nat remove Set ==="
  echo "#########################"
  read -p "Please input remove export port num: " nport
  read -p "Please input remove proto(tcp/udp): " nproto
  read -p "Please input remove inner toport num: " ntoport
  read -p "Please input remove toaddr(private ip addr): " ntoaddr
  firewall-cmd --permanent --zone=external --remove-forward-port=port=$nport:proto=$nproto:toport=$ntoport:toaddr=$ntoaddr
  firewall-cmd --reload
  firewall-cmd --zone=external --list-all | grep -e toaddr
  ;;

  *)
  echo "plz input some ward"
  echo "1) config insert firewall nat set     2)remove firewall nat set"
  echo "Usage: firewall_nat_set_centos8.sh 1"
esac

 

 

firewall_nat_set_centos.txt
0.00MB

 

 

실행

[root@techpicnic ~]# sh firewall_nat_set_cen7.sh 1
  forward-ports: port=xxxx:proto=tcp:toport=40000:toaddr=192.168.x.x
        port=xxxx3:proto=tcp:toport=40001:toaddr=192.168.x.x
        port=xxxx2:proto=tcp:toport=40002:toaddr=192.168.x.x
        port=xxxx3:proto=tcp:toport=40003:toaddr=192.168.x.x
        port=xxxx3:proto=tcp:toport=40004:toaddr=192.168.x.x
        port=xxxx5:proto=tcp:toport=3389:toaddr=192.168.x.x
        port=xxxx8:proto=tcp:toport=22:toaddr=192.168.x.x
#######################
=== Firewall nat add Set ===
#######################
Please input export port num: 1234
Please input proto(tcp/udp): tcp
Please input inner toport num: 1234
Please input toaddr(private ip addr): 192.168.x.x
success
success

  forward-ports: port=xxxx:proto=tcp:toport=40000:toaddr=192.168.x.x
        port=xxxx3:proto=tcp:toport=40001:toaddr=192.168.x.x
        port=xxxx2:proto=tcp:toport=40002:toaddr=192.168.x.x
        port=xxxx3:proto=tcp:toport=40003:toaddr=192.168.x.x
        port=xxxx3:proto=tcp:toport=40004:toaddr=192.168.x.x
        port=xxxx5:proto=tcp:toport=3389:toaddr=192.168.x.x
        port=xxxx8:proto=tcp:toport=22:toaddr=192.168.x.x

        port=1234:proto=tcp:toport=1234:toaddr=192.168.x.x

[root@techpicnic ~]#