Iptables-外网地址及端口映射到内网地址及端口
1.要求:
把外部IP地址及端口映射到内部服务器地址及端口 在10段主机可以通过访问10.0.0.141:80,即可访问到192.168.1.17:9000 提供的web服务 |
2.192.168.1.17主机web环境搭建
[root@test ~]# yum install epel-release -yum [root@test ~]# yum install nginx -y[root@test ~]# systemctl start nginx [root@test nginx]# egrep -v “#|^$” nginx.conf.default > nginx.conf [root@test nginx]# mkdir html/www/ -p [root@test nginx]# echo test > html/www/index.html [root@test nginx]# cat nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 9000; server_name www.test.com; location / { root /etc/nginx/html/www; index index.html index.htm; } } } [root@test nginx]# systemctl restart nginx |
3.10.0.0.17配置
[root@liang ~]# echo “192.168.1.17 www.test.com” >> /etc/hosts [root@liang ~]# curl www.test.com:9000 test [root@liang ~]# iptables -t nat -A PREROUTING -d 10.0.0.141 -p tcp —dport 80 \ -j DNAT —to-destination 192.168.1.17:9000 |
4.测试:
还没有评论,来说两句吧...