搭建NAT64/DNS6实现IPv4/v6转换

NAT64采用tayga实现,DNS64采用bind9.8实现。

1 平台搭建

平台为ubuntu12.04 Desktop版本。正常安装即可。

2 NAT64(tayga)

2.1 安装

在终端模式下输入

sudo apt-get install tayga

2.2 配置

2.2.1 相关设置

sudo gedit /etc/tayga.conf

按照说明配置,目前实现方案不需要修改。

2.2.2 创建、启动设备

tayga –mktun
ip link set nat64 up

2.2.3 地址、路由配置

ip addr add 192.168.0.1 dev nat64  (修改为本机IPv4地址)   
ip addr add 2001:db8:1::1 dev nat64 (修改为本机IPv6地址)
ip route add 192.168.255.0/24 dev nat64(不需要修改)
ip route add 2001:db8:1:ffff::/96 dev nat64(不需要修改)

2.2.4 启动IPv4、IPv6转发

sysctl -w net.ipv4.conf.all.forwarding=1
sysctl -w net.ipv6.conf.all.forwarding=1

2.2.5 启动tayga

tayga

可使用tayga –d进入debug模式。

ping6 2001:db8:1:ffff::192.168.0.1(192.168.0.1修改为本机IPv4地址)

2.2.6 NAT64设置

iptables -t nat -A POSTROUTING -s 192.168.255.0/24 -j SNAT --to-source 192.168.0.1 (修改为本机IPv4地址)
iptables -A FORWARD -s 192.168.255.0/24 -i nat64 -j ACCEPT

3 DNS64 bind9

3.1 安装

sudo apt-get install bind9

3.2 配置

sudo gedit /etc/bind/named.conf.options

修改为如下:

options {
	directory "/var/cache/bind";

	// If there is a firewall between you and nameservers you want
	// to talk to, you may need to fix the firewall to allow multiple
	// ports to talk.  See http://www.kb.cert.org/vuls/id/800113

	// If your ISP provided one or more IP addresses for stable 
	// nameservers, you probably want to use them as forwarders.  
	// Uncomment the following block, and insert the addresses replacing 
	// the all-0's placeholder.
        listen-on-v6 { any; };
        allow-query { any; };
        dns64 2001:db8:1:ffff::/96 {
                clients { any; };
        };
	 forwarders {
	 	8.8.8.8; //DNS地址
         };

//=================================================================
// If BIND logs error messages about the root key being expired,
// you will need to update your keys.  See https://www.isc.org/bind-keys
//================================================================
	dnssec-validation auto;

	auth-nxdomain no;    # conform to RFC1035
	listen-on-v6 { any; };
};

修改完成后,输入 named.conf查看修改是否成功。

3.3 启动bind9

Bind9默认安装后开机启动。设置完成后,输入

/etc/init.d/bind restart

4 使用

4.1 Windows

用管理员权限进入cmd,输入

netsh
>interface ipv6
>add route 2001:db8:1:ffff::/96(修改为机器的ipv6地址) "本地连接" 2001:db8:1::1(修改为服务器的ipv6地址)

然后设置DNS服务器为NAT64地址即可

4.2 Linux

添加路由

ip route add 2001:db8:1:ffff::/96 (修改为机器的ipv6地址) via 2001:db8:1::1
(为服务器的ipv6地址)

然后设置DNS服务器为NAT64地址即可

注:
本文中服务器地址为:192.168.130.42
2400:dd01:1001:130:250:c2ff:fe23:f051/64

你可能感兴趣的:(日常小技能,服务器,linux)