简介
NAT(Network Address Translation,网络地址转换)。借助于NAT,私有(保留)地址的"内部"网络通过路由器发送数据包时,私有地址被转换成合法的IP地址,一个局域网只需使用少量IP地址(甚至是1个)即可实现私有地址网络内所有计算机与Internet的通信需求。
举个栗子!
guest IP:192.168.122.2
host IP :10.200.200.100
虚拟机访问外部网络,数据包 ip 地址变化如下
192.168.122.2 --> www.baidu.com
10.200.200.100 --> www.baidu.com
www.baidu.com --> 10.200.200.100
www.baidu.com --> 192.168.122.2
NAT 模式 需要物理机内核支持 NAT 相关的选项
如下
#
# Core Netfilter Configuration
#
CONFIG_NETFILTER_NETLINK=m
CONFIG_NF_NAT=m
CONFIG_NF_NAT_NEEDED=y
CONFIG_NF_NAT_PROTO_DCCP=y
CONFIG_NF_NAT_PROTO_UDPLITE=y
CONFIG_NF_NAT_PROTO_SCTP=y
CONFIG_NF_NAT_AMANDA=m
CONFIG_NF_NAT_FTP=m
CONFIG_NF_NAT_IRC=m
CONFIG_NF_NAT_SIP=m
CONFIG_NF_NAT_TFTP=m
CONFIG_NF_NAT_REDIRECT=m
检查 NAT 相关模块是否加载
[root@localhost ~]# lsmod | grep nat
nf_nat_masquerade_ipv4 13463 1 ipt_MASQUERADE
ebtable_nat 12807 1
ip6table_nat 12864 1
iptable_nat 12875 1
ebtables 35009 3 ebtable_broute,ebtable_nat,ebtable_filter
ip6_tables 26912 5 ip6table_filter,ip6table_mangle,ip6table_security,ip6table_nat,ip6table_raw
ip_tables 27126 5 iptable_security,iptable_filter,iptable_mangle,iptable_nat,iptable_raw
nf_nat_ipv6 14131 2 openvswitch,ip6table_nat
nf_nat_ipv4 14115 2 openvswitch,iptable_nat
nf_nat 26583 4 openvswitch,nf_nat_ipv4,nf_nat_ipv6,nf_nat_masquerade_ipv4