pve網路配置 虛擬機外部連服務
修改/etc/network/interfaces
# Loopback interface
auto lo
iface lo inet loopback
# 主網卡配置
auto eno1
iface eno1 inet static
address 120.120.XXX.XXX
netmask 255.255.255.0
gateway 120.126.XXX.XXX
post-up echo 1 > /proc/sys/net/ipv4/ip_forward
# 虛擬網橋配置
auto vmbr0
iface vmbr0 inet static
address 192.168.1.1
netmask 255.255.255.0
bridge-ports none
bridge-stp off
bridge-fd 0
---------------------
auto lo
iface lo inet loopback
auto eno1
iface eno1 inet static
address 120.120.XXX.XXX
netmask 255.255.255.0
gateway 120.120.XXX.XXX
auto vmbr0
iface vmbr0 inet static
address 192.168.1.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 iptables -t nat -A POSTROUTING -s '192.168.1.1/24' -o eno1 -j MASQUERADE
post-down iptables -t nat -D POSTROUTING -s '192.168.1.1/24' -o eno1 -j MASQUERADE
post-up iptables -t raw -I PREROUTING -i fwbr+ -j CT --zone 1
post-down iptables -t raw -D PREROUTING -i fwbr+ -j CT --zone 1
/etc/rc.local
自定義的 iptables
*nat:PREROUTING ACCEPT [0:0]:POSTROUTING ACCEPT [0:0]-A POSTROUTING -s 192.168.1.0/24 -o eno1 -j MASQUERADE-A PREROUTING -p tcp --dport 8083 -j DNAT --to-destination 192.168.1.3:80-A POSTROUTING -p tcp -d 192.168.1.3 --dport 80 -j MASQUERADE-A PREROUTING -p tcp --dport 8084 -j DNAT --to-destination 192.168.1.4:80-A POSTROUTING -p tcp -d 192.168.1.4 --dport 80 -j MASQUERADECOMMIT
保存後
iptables-restore < /etc/rc.local
檢查網路接口ifreload -aip addr show
-------------------------------CentOS 6 默認使用 iptables
作為防火牆,檢查是否阻止了 80
端口
iptables -L -n -v
確保有類似以下規則:
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80
如果沒有,添加規則允許 80
端口:
iptables -I INPUT -p tcp --dport 80 -j ACCEPTservice iptables save
檢查防火牆規則是否已保存:iptables -L -n -v
虛擬機內部測試 Nginx 是否正常服務:curl http://localhost
從外部測試:
curl http://120.120.X.X:8083
網卡查詢ip link show eth1
類似以下eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether 00:1a:2b:3c:4d:5e brd ff:ff:ff:ff:ff:ff
這裡的 00:1a:2b:3c:4d:5e
是實際的 MAC 地址。bc:24:11:a1:32:6d
編輯網卡的配置
vi /etc/sysconfig/network-scripts/ifcfg-eth1
如果不匹配,請將其更新為正確的值。HWADDR=00:1A:2B:3C:4D:5E
留言
張貼留言