Hetnzer Proxmox 配置独立ipv6和ipv4 NAT

配置网卡文件

/etc/network/interfaces


auto lo
iface lo inet loopback
iface lo inet6 loopback

auto enp41s0
iface enp41s0 inet manual
#  post-up /sbin/ethtool -K enp41s0 tx off rx off
iface enp41s0 inet6 manual

auto vmbr0
iface vmbr0 inet static
  address 46.4.23.244 #母鸡IP
  netmask 255.255.255.192 #母鸡子网掩码
  gateway 46.4.23.193 #母鸡网关
  pointopoint 46.4.23.193 #母鸡网关(点对点连接参数)
  hwaddress ether d0:50:99:fd:d6:13 #MAC地址
  bridge_ports enp41s0 #物理网卡名字
  bridge_stp off
  bridge_fd 0
  bridge_maxwait 0
  # post-up /sbin/ethtool -K vmbr0 tx off rx off

iface vmbr0 inet6 static
  address 2a01:4f8:221:38d9::2 #IPv6
  netmask 64 
  gateway fe80::1 #v6网关
  bridge_ports enp41s0
  bridge_stp off
  bridge_fd 0
  up ip -6 route del 2a01:4f8:221:38d9::/64 dev vmbr0

auto vmbr1
iface vmbr1 inet static
  address 192.168.1.1 #内网网卡 v4
  netmask 255.255.255.0 #子网掩码 /24
  bridge_ports none
  bridge_stp off
  bridge_fd 0
  post-up echo 1 > /proc/sys/net/ipv4/ip_forward #启用 IPv4 转发功能
  post-up iptables -t nat -A POSTROUTING -s '192.168.1.0/24' -o vmbr0 -j MASQUERADE
  post-down iptables -t nat -D POSTROUTING -s '192.168.1.0/24' -o vmbr0 -j MASQUERADE

auto vmbr1
iface vmbr1 inet6 static
  address  2a01:4f8:221:38d9::3/64   
  #gateway fe80::1
  bridge_ports none
  bridge_stp off
  bridge_fd 0
  up ip -6 route add 2a01:4f8:221:38d9::/64 dev vmbr1 #添加指定的 IPv6 路由到 vmbr1 接口

配置sysctl.conf

/etc/sysctl.conf

net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr 
net.ipv4.ip_forward=1
net.ipv6.conf.all.accept_dad = 1
net.ipv6.conf.all.accept_ra = 0
net.ipv6.conf.all.accept_redirects = 1
net.ipv6.conf.all.accept_source_route = 0
net.ipv6.conf.all.autoconf = 0
net.ipv6.conf.all.disable_ipv6 = 0
net.ipv6.conf.all.forwarding=1

sysctl -p

net.core.default_qdisc=fq: 这个参数设置默认的队列调度算法为fq(Fair Queueing)。fq是一种公平的队列调度算法,用于网络流量管理。
net.ipv4.tcp_congestion_control=bbr: 开启bbr
net.ipv4.ip_forward=1: 这个参数启用IPv4数据包的转发。当这个值设置为1时,Linux系统将会转发接收到的IP数据包。
net.ipv6.conf.all.accept_dad = 1: 这个参数设置IPv6接口在启动时接受DAD(Duplicate Address Detection)。
net.ipv6.conf.all.accept_ra = 0: 这个参数设置IPv6接口不接受路由器通告(Router Advertisements)。
net.ipv6.conf.all.accept_redirects = 1: 这个参数设置IPv6接口接受重定向信息。
net.ipv6.conf.all.accept_source_route = 0: 这个参数设置IPv6接口不接受源路由选项。
net.ipv6.conf.all.autoconf = 0: 这个参数禁用IPv6自动配置。
net.ipv6.conf.all.disable_ipv6 = 0: 这个参数启用IPv6支持。
net.ipv6.conf.all.forwarding=1: 这个参数启用IPv6数据包的转发。
sysctl -p: 这个命令用于加载新的sysctl设置,使其生效。


配置NAT端口复用(iptables)

apt-get install iptables-persistent #安装iptables

vim /etc/iptables/rules.v4

*nat
:PREROUTING ACCEPT [17:1000]
:INPUT ACCEPT [16:960]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A PREROUTING -p tcp -m tcp --dport 40000:44999 -j DNAT --to-destination 10.1.1.16:40000-44999
-A PREROUTING -p tcp -m tcp --dport 35000:39999 -j DNAT --to-destination 10.1.1.15:35000-39999
-A PREROUTING -p tcp -m tcp --dport 30000:34999 -j DNAT --to-destination 10.1.1.14:30000-34999
-A PREROUTING -p tcp -m tcp --dport 25000:29999 -j DNAT --to-destination 10.1.1.13:25000-29999
-A PREROUTING -p tcp -m tcp --dport 20000:24999 -j DNAT --to-destination 10.1.1.12:20000-24999
-A PREROUTING -p tcp -m tcp --dport 15000:19999 -j DNAT --to-destination 10.1.1.11:15000-19999
-A PREROUTING -p tcp -m tcp --dport 10000:14999 -j DNAT --to-destination 10.1.1.10:10000-14999
COMMIT


保存然后储存放用
iptables-restore /etc/iptables/rules.v4

然后
vim /etc/network/if-pre-up.d/iptables

改成以下内容
#!/bin/sh
/sbin/iptables-restore < /etc/iptables/rules.v4

chmod +x /etc/network/if-pre-up.d/iptables

最后检查一下就可以,重启网络,最后重启

systemctl restart networking.service #重启网络
systemctl status networking.service #查看网络状态

这个配置我们的小机器的网卡配置需要注意:

首先注意 :V6和V4 都是接vmbr1 ,不要直接接vmbr0

Hetnzer Proxmox 配置独立ipv6和ipv4 NAT

给TA打赏
共{{data.count}}人
人已打赏
建站

Memos的安装使用以及Docker的安装

2023-11-8 22:50:33

WordPress主题

Puma – 文艺超简 WordPress 博客主题

2020-4-22 10:07:13

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索