Bash/Port/Forward: Difference between revisions
Jump to navigation
Jump to search
Line 44: | Line 44: | ||
==Forwarding rule remove== | ==Forwarding rule remove== | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
iptables -t nat -D PREROUTING | iptables -t nat -D PREROUTING -p tcp -m tcp -d $CKI_WAN_ADDR --dport $CKI_WAN_PORT -j DNAT --to-destination $CKI_LAN_ADDR:$CKI_LAN_PORT | ||
iptables -D FORWARD -m state -p tcp -d $CKI_LAN_ADDR --dport $CKI_LAN_PORT --state NEW,ESTABLISHED,RELATED -j ACCEPT | iptables -D FORWARD -m state -p tcp -d $CKI_LAN_ADDR --dport $CKI_LAN_PORT --state NEW,ESTABLISHED,RELATED -j ACCEPT | ||
iptables -t nat -D POSTROUTING -p tcp -m tcp -s $CKI_LAN_ADDR --sport $CKI_LAN_PORT -j SNAT --to-source $CKI_WAN_ADDR | iptables -t nat -D POSTROUTING -p tcp -m tcp -s $CKI_LAN_ADDR --sport $CKI_LAN_PORT -j SNAT --to-source $CKI_WAN_ADDR |
Revision as of 23:47, 10 June 2018
Check Port is not used
# check port 22200
fuser 22200/tcp
# check port 55500
fuser 55500/tcp
Enable Specific Port
firewall-cmd --zone=public --permanent --add-port=22200/tcp
firewall-cmd --zone=public --permanent --add-port=55500/tcp
firewall-cmd --reload
netstat
Enable Range of Port
firewall-cmd --zone=public --permanent --add-port=22200-22299/tcp
firewall-cmd --zone=public --permanent --add-port=55500-55599/tcp
firewall-cmd --reload
netstat
Forwarding Parameters
# destination ip & port
CKI_LAN_ADDR=100.43.0.20
CKI_LAN_PORT=22211
# wan interface ip & port
CKI_WAN_ADDR=139.59.51.80
CKI_WAN_PORT=22200
Forwarding rule add
iptables -t nat -A PREROUTING -p tcp -m tcp -d $CKI_WAN_ADDR --dport $CKI_WAN_PORT -j DNAT --to-destination $CKI_LAN_ADDR:$CKI_LAN_PORT
iptables -A FORWARD -m state -p tcp -d $CKI_LAN_ADDR --dport $CKI_LAN_PORT --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A POSTROUTING -p tcp -m tcp -s $CKI_LAN_ADDR --sport $CKI_LAN_PORT -j SNAT --to-source $CKI_WAN_ADDR
Forwarding rule remove
iptables -t nat -D PREROUTING -p tcp -m tcp -d $CKI_WAN_ADDR --dport $CKI_WAN_PORT -j DNAT --to-destination $CKI_LAN_ADDR:$CKI_LAN_PORT
iptables -D FORWARD -m state -p tcp -d $CKI_LAN_ADDR --dport $CKI_LAN_PORT --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -D POSTROUTING -p tcp -m tcp -s $CKI_LAN_ADDR --sport $CKI_LAN_PORT -j SNAT --to-source $CKI_WAN_ADDR