1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > Linux端口转发 端口映射相关 (iptables实现)

Linux端口转发 端口映射相关 (iptables实现)

时间:2022-06-14 05:03:21

相关推荐

Linux端口转发 端口映射相关 (iptables实现)

一、本地端口映射

即访问192.168.10.11:8080 访问到192.168.10.11:80

iptables -t nat -A PREROUTING -p tcp --dport 8080 -j REDIRECT --to-ports 80

二、异地端口映射

即访问192.168.10.11:8080 访问到192.168.10.20:80

注:虚拟机配置过程中,需打开端口,开启转发等功能;

云上部署时,虽然云服务器中有安全组,但是在利用iptables进行转发时,同时需要利用iptables进行端口开启。之后进行端口转发;

如上操作,可参考:Linux用iptables实现网站访问重定向_服务器应用_Linux公社-Linux系统门户网站 ()

1、开启转发功能

vim /etc/sysctl.conf添加如下:net.ipv4.ip_forward = 1 (永久开启转发功能)sysctl -p

2、配置

# iptables -t nat -A PREROUTING -p tcp -d 192.168.10.11 --dport 8080 -j DNAT --to-destination 192.168.10.20:80# iptables -t nat -A POSTROUTING -p tcp -s 192.168.10.20 --sport 80 -j SNAT --to-source 192.168.10.11

三、问题处理

1、没有iptables服务

systemctl stop firewalldsystemctl mask firewalldyum install iptables.servicessystemctl enable iptablessystemctl start iptables

2、开启某个端口

iptables -I INPUT -p tcp --dport 8080 -j ACCEPT (开启8080端口)

3、关于规则保存

service iptables savesystemctl restart iptables

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。