CPU:Intel Xeon E3-1231v3 - 4c/8t - 3.4 GHz/3.8 GHz
RAM:32 GB 1333 MHz
NETWORK:100 Mbps incoming 1000 Mbps outgoing
从头演示如何在pve中nat小鸡自动获取ip地址,并且将nat小鸡中的端口映射到母鸡ip,使用母鸡ip加小鸡端口访问小鸡服务
准备环境
- 一台配置较好的独立服务器
- 勤劳的小手
步骤
配置nat小鸡自动获取ip地址
首先先更新一下系统组件
apt update && apt upgrade
编辑/etc/network/interface文件后保存
nano /etc/network/interfaces
auto lo
iface lo inet loopback
iface eno1 inet manual
auto vmbr0
iface vmbr0 inet static
address 149.202.**.**/24
gateway 149.202.**.**
bridge-ports eno1
bridge-stp off
bridge-fd 0
hwaddress 00:1E:67:FA:**:**
iface vmbr0 inet6 static
address 2001:41d0:**:**::1/128
gateway 2001:41d0:**:**:ff:ff:ff:ff
# 添加网卡vmbr1
auto vmbr1
iface vmbr1 inet static
address 192.168.100.1
netmask 255.255.255.0
bridge_ports none
bridge_stp off
bridge_fd 0
post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-up echo 1 > /proc/sys/net/ipv4/conf/vmbr1/proxy_arp
post-up iptables -t nat -A POSTROUTING -s '192.168.100.0/24' -o vmbr0 -j MASQUERADE
post-down iptables -t nat -D POSTROUTING -s '192.168.100.0/24' -o vmbr0 -j MASQUERADE
重启网络服务使其生效
systemctl restart networking
安装dhcp服务(安装默认无法启动,需要配置后方能启动)
apt-get install isc-dhcp-server
配置dhcp服务
nano /etc/default/isc-dhcp-server
INTERFACESv4="vmbr1"
INTERFACESv6=""
nano /etc/dhcp/dhcpd.conf
option domain-name "ks2.topwuan.tech";
option domain-name-servers 8.8.8.8, 8.8.4.4;
default-lease-time 600;
max-lease-time 7200;
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.5 192.168.100.230;
option subnet-mask 255.255.255.0;
option domain-name-servers 8.8.8.8, 8.8.4.4;
option domain-name "ks2.topwuan.tech";
option routers 192.168.100.1;
option netbios-name-servers 192.168.100.1;
option netbios-node-type 8;
get-lease-hostnames true;
use-host-decl-names true;
default-lease-time 600;
max-lease-time 7200;
interface vmbr1;
}
重启dhcp服务并检查服务是否正常
systemctl restart isc-dhcp-server
systemctl status isc-dhcp-server
在创建小鸡时网络接口选择vmbr1,进入系统输入
查看ip信息发现已经自动获取到dhcp分配的ip了ip a
使用rinetd实现nat端口转发
安装rinetd
apt install rinetd
配置端口转发
nano /etc/rinetd.conf
logfile /var/log/rinetd.log
0.0.0.0 2322 192.168.100.6 22 #将192.168.100.6的22端口映射到母鸡的2322,0.0.0.0表示母鸡绑定的所有IP,这里可以直接填公网IP
重启rinetd,接下来就可以使用公网ip加转发的端口访问小鸡的服务了
systemctl restart rinetd
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容