LINUX

it2023-06-10  119

一.DNAT概述 1.DNAT 的全称为Destination Network Address Translation目的地址转换,常用于防火墙中。 目的地址转换的作用是将一组本地内部的地址映射到一组全球地址。通常来说,合法地址的数量比起本地内部的地址数量来要少得多。RFC1918中的地址保留可以用地址重叠的方式来达到。当一个内部主机第一次放出的数据包通过防火墙时,动态NAT的实现方式与静态NAT相同,然后这次NAT就以表的形式保留在防火墙中。

2.DNAT策略的典型应用环境 在Internet中发布位于企业局域网内的服务器 3.DNAT的过程(图解)

二.DNAT实验测试 ①实验环境 两台CentOS8 实验步骤 互联网中的主机访问内网的服务器 ①一台虚拟机当做网关服务器,网络适配器一块为桥接(ens38)一块为hostonly(ens39) ②hostonly网卡配置为

[root@localhost network-scripts]# cat ifcfg-ens37 TYPE="Ethernet" BOOTPROTO="static" 静态配置 NAME="ens37" DEVICE="ens37" IPADDR=192.168.52.128 与VMnet1同一网段即可 NETMASK=255.255.255.0 ONBOOT="yes"

③桥接网卡(真实上网)

[root@localhost network-scripts]# cat ifcfg-ens38 TYPE="Ethernet" BOOTPROTO="static" NAME="ens38" DEVICE="ens38" IPADDR=172.20.xx.x与你的真实机器的ip地址在同一网段即可 NETMASK=255.255.255.240 GATEWAY=172.20.xx.x 与真实机器相同 DNS1=172.20.xx.x 与真实机器相同 DNS2=114.114.114.114 ONBOOT="yes"

④另一台当做mariadb+nginx服务器 网络适配器为hostonly hostonly配置

BOOTPROTO=static NAME=ens39 DEVICE=ens39 IPADDR=192.168.52.131 同一网段即可 NETMASK=255.255.255.0 GATEWAY=192.168.52.128 网关服务器的hostonly的IP地址,因为我们需要网关服务器做路由转发 DNS1=114.114.114.114 ONBOOT=yes

⑤安装mariadb+nginx

yum install mariadb mariadb-server -y yum install nginx -y 安装完成之后 开启服务 service mariadb start 连接mysql [root@localhost network-scripts]# mysql -uroot -p Enter password: (回车即可默认密码为空) Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 16 Server version: 10.3.17-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> 创建一个用户,密码为123456 grant all on *.* to 'zhangsan'@'%' identified by '123456'; 开启nginx之前需要关闭httpd防止占用80端口 service httpd stop service nginx start

⑥网关服务器iptables,以及路由配置

#临时开启路由功能 echo 1 >/proc/sys/net/ipv4/ip_forward #在iptables里添加一条snat的转发策略,让内网192.168.52.0的网络从ens38接口出去,出去的时候将源ip地址转换为桥接ip地址 iptables -t nat -A POSTROUTING -s 192.168.52.0/24 -o ens38 -j SNAT --to-source 桥接ip地址 #dnat策略-web iptables -t nat -A PREROUTING -i ens38 -d 桥接ip地址 -p tcp --dport 80 -j DNAT --to-destination 192.168.52.131 #dnat策略-mysql iptables -t nat -A PREROUTING -i ens38 -d 桥接ip地址 -p tcp --dport 3306 -j DNAT --to-destination 192.168.52.131
最新回复(0)