#!/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
실행
[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 ~]#
'shell_script' 카테고리의 다른 글
shell - centos7-minimal 버전 초기 세팅 스크립트 (0) | 2021.08.18 |
---|---|
shell - public cloud AWS (0) | 2021.08.17 |
shell - 패스워드 생성 법칙 적용 (0) | 2021.08.11 |
shell - 환경변수 설정 (0) | 2021.08.07 |
shell - system 관련 스크립트 (0) | 2021.08.02 |