Bash/Port/Forward: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 22: | Line 22: | ||
firewall-cmd --reload | firewall-cmd --reload | ||
netstat | netstat | ||
</syntaxhighlight> | |||
==Forwarding Parameters== | |||
<syntaxhighlight lang="bash"> | |||
# destination ip & port | |||
MSC_LAN_ADDR=100.43.0.20 | |||
MSC_LAN_PORT=22211 | |||
# wan interface ip & port | |||
MSC_WAN_ADDR=139.59.51.80 | |||
MSC_WAN_PORT=22200 | |||
</syntaxhighlight> | |||
==Forwarding rule add== | |||
<syntaxhighlight lang="bash"> | |||
iptables -t nat -A PREROUTING -p tcp -m tcp -d $MSC_WAN_ADDR --dport $MSC_WAN_PORT -j DNAT --to-destination $MSC_LAN_ADDR:$MSC_LAN_PORT | |||
iptables -A FORWARD -m state -p tcp -d $MSC_LAN_ADDR --dport $MSC_LAN_PORT --state NEW,ESTABLISHED,RELATED -j ACCEPT | |||
iptables -t nat -A POSTROUTING -p tcp -m tcp -s $MSC_LAN_ADDR --sport $MSC_LAN_PORT -j SNAT --to-source $MSC_WAN_ADDR | |||
</syntaxhighlight> | |||
==Forwarding rule remove== | |||
<syntaxhighlight lang="bash"> | |||
iptables -t nat -D PREROUTING -p tcp -m tcp -d $MSC_WAN_ADDR --dport $MSC_WAN_PORT -j DNAT --to-destination $MSC_LAN_ADDR:$MSC_LAN_PORT | |||
iptables -D FORWARD -m state -p tcp -d $MSC_LAN_ADDR --dport $MSC_LAN_PORT --state NEW,ESTABLISHED,RELATED -j ACCEPT | |||
iptables -t nat -D POSTROUTING -p tcp -m tcp -s $MSC_LAN_ADDR --sport $MSC_LAN_PORT -j SNAT --to-source $MSC_WAN_ADDR | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 23:30, 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-22290/tcp
firewall-cmd --zone=public --permanent --add-port=55500-55590/tcp
firewall-cmd --reload
netstat
Forwarding Parameters
# destination ip & port
MSC_LAN_ADDR=100.43.0.20
MSC_LAN_PORT=22211
# wan interface ip & port
MSC_WAN_ADDR=139.59.51.80
MSC_WAN_PORT=22200
Forwarding rule add
iptables -t nat -A PREROUTING -p tcp -m tcp -d $MSC_WAN_ADDR --dport $MSC_WAN_PORT -j DNAT --to-destination $MSC_LAN_ADDR:$MSC_LAN_PORT
iptables -A FORWARD -m state -p tcp -d $MSC_LAN_ADDR --dport $MSC_LAN_PORT --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A POSTROUTING -p tcp -m tcp -s $MSC_LAN_ADDR --sport $MSC_LAN_PORT -j SNAT --to-source $MSC_WAN_ADDR
Forwarding rule remove
iptables -t nat -D PREROUTING -p tcp -m tcp -d $MSC_WAN_ADDR --dport $MSC_WAN_PORT -j DNAT --to-destination $MSC_LAN_ADDR:$MSC_LAN_PORT
iptables -D FORWARD -m state -p tcp -d $MSC_LAN_ADDR --dport $MSC_LAN_PORT --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -D POSTROUTING -p tcp -m tcp -s $MSC_LAN_ADDR --sport $MSC_LAN_PORT -j SNAT --to-source $MSC_WAN_ADDR