如何在 Google Compute Engine 上的 Centos 6 上 WHM/Cpanel 上的 Nat 配置中修复本地 IP

How to fix local IP in Nat Configuration on WHM/Cpanel on Centos 6 on Google Compute Engine

如果您在 Centos 6 Cpanel 服务器上的 Google Compute Engine 上删除了一个 VM,然后使用相同的磁盘创建它,即使您保留了静态 IP,通常也会为您分配一个新的本地 IP 地址。这不会正确更新 Cpanel/WHM 服务器上的 NAT 配置。

这会阻止任何站点运行,唯一的修复方法是手动编辑 http.conf 文件。在 Web Host Manager 中,您可以修复面向 public 的 IP,但是没有地方可以编辑本地 IP。有谁知道如何在 Google Compute Engine 上编辑 centos 6 上的 nat 配置以修复本地 IP,以便创建的所有新站点都将在 http.conf 中具有正确的本地 IP?

这是我的 Centos 6 服务器上当前 nat 配置的图片。

这是一张显示我在 Compute Engine 中的正确本地 IP 的图片,您可以看到它与 Cpanel 拥有的不匹配,这导致 http.conf 文件生成具有错误 IP 的新虚拟主机。

计算引擎不允许您创建具有特定网络 IP 地址的实例。您必须结合使用路由和实例的 --can-ip-forward 功能来添加 IP 地址作为静态网络 IP 地址,然后映射到您想要的虚拟机实例。

例如,如果您想将 10.1.1.1 作为网络 IP 地址专门分配给虚拟机实例,您可以创建一个静态路由,将流量从 10.1.1.1 发送到您的实例,即使实例的网络Compute Engine 分配的 IP 地址与您所需的网络 IP 地址不匹配。

看看这个link:https://cloud.google.com/compute/docs/instances-and-network#staticnetworkaddress

这是 WHM/Cpanel 中的一个配置问题,无法通过界面中的任何配置设置进行更正。我联系了 Cpanel 支持,他们为我提供了一个从 root 到 运行 的命令行 shell 脚本来解决这个问题。它运行完美:

# /scripts/build_cpnat

这解决了问题,但如果这不能解决您的问题,他们会提供额外的信息:

If this does not resolve your issue, please review our NAT documentation and ensure that your server is configured in a supported 1:1 NAT configuration: http://documentation.cpanel.net/display/ALD/1%3A1+NAT

我只需要将本地 IP 更改为新 IP:

/var/cpanel/cpnat
/etc/hosts
/etc/ips.dnsmaster

如果还是不行,试试这个:

(即,当您列出帐户时,您会看到为每个帐户列出的旧内部 IP)

WHM -> List Accounts expand desired account (+)
    => Change IP Address
    => select the IP address (even if it is the same external IP)
    => click change.

对每个受影响的帐户重复。

输出:

The remote dns zone is not consistent with the httpd.conf.
The current ip in httpd.conf is: 10.240.0.3.
The current ip in the dns zone is: 104.154.68.68!

104.154.68.68 will be switched to the new ip as well!

The local dns zone is not consistent with the httpd.conf.
The current ip in httpd.conf is: 10.240.0.3.
The current ip in the dns zone is: 10.240.0.2!

10.240.0.2 will be switched to the new ip as well!

Warning, serious database inconsistency. httpd.conf, local dns, and remote dns all
have different ideas about what the ip address of this site really is. They will now all be changed
to the new ip: 10.240.0.2!

Changed all instances of [10.240.0.3,104.154.68.68] -> [104.154.68.68] in dcmetroc.kellen.hosting
Changed all instances of [10.240.0.3,104.154.68.68] -> [104.154.68.68] in dcmetrocollaborative.org
Updating httpd.conf....Done
System has 0 free ips.

如果您使用的是 nginx,请不要忘记在 ngnix 插件中重建虚拟主机!

我在托管最新 WHM/cPanel 的 AWS 和 CentOS 7 上遇到了同样的问题。每次实例重新启动时,都会有一个新的私有/本地 IP 地址。我从 /var/cpanel/.

中删除了 cpnat

所以我禁用了 NAT,然后我创建了另一个 eth,这样我就可以使用静态 IP 配置它,即 Public IP,然后仅针对拥有 WHM 的主机名和域名的主帐户将其分配给本地 IP 地址,但由于本地 IP 地址不断变化,所以我创建了一个脚本,每次启动后都会在开始时启动,收集新的本地 IP 地址并将其自动分配给主帐户,如果没有新的本地IP 地址然后脚本退出而不做任何事情。

这里是完成的步骤:

nano /etc/sysconfig/network-scripts/ifcfg-eth0:cp1

并在该文件中放入以下内容:(更改 IPADDR 和 DNS)

DEVICE="eth0:cp1"
BOOTPROTO="static"
ONBOOT="yes"
IPADDR="13.54.100.XX"
NETMASK="255.255.255.0"
DNS1="172.31.0.2"
TYPE="Ethernet"
IPV6INIT="no"

现在我们希望这个界面在重启时保留并在重启时启动,所以 运行:

ifup eth0:cp1

然后通过以下方式重新启动网络服务: 服务网络重启

现在通过删除 /var/cpanel

中的文件 cpnat 来禁用 NAT 模式

现在检查文件 /var/cpanel/mainip 并确保我们的外部 IP 是 13.54。100.XX 使用 nano 创建以下文件:

nano /etc/init.d/fixdhcp

将以下内容添加到文件并保存:

#!/bin/bash
# # This script assigns available DHCP IP to ACCOUNT-NAME user on Reboot or Restart, please change ACCOUNT-NAME to the main WHM domain account name
# apache service will restart when done.    

/scripts/rebuildippool
export mydhcp10=$(cat /etc/ipaddrpool)
echo $mydhcp10

# Exit if no available IPs
if [ "${mydhcp10}" == "" ]; then
echo "ipaddrpool is empty" && exit 1
else
echo "ipaddrpool is not empty"
fi

/usr/local/cpanel/bin/setsiteip -u ACCOUNT-NAME $mydhcp10
chmod +x /etc/rc.d/rc.local
echo finished now restarting services
/scripts/rebuildhttpdconf
/scripts/rebuildippool
/scripts/cleandns
/scripts/fixvaliases
/scripts/modify_accounts --theme=paper_lantern --all-users
/usr/local/cpanel/scripts/updateuserdomains
service httpd restart

使文件可执行:

chmod +x /etc/init.d/fixdhcp

将其添加到 rc.d

nano /etc/rc.local

然后像这样添加:

/etc/init.d/fixdhcp

然后保存 运行:

chmod +x /etc/rc.d/rc.local

最佳和最简单的解决方案是使用 WHM/Cpanel IP 迁移向导 选项更改现有的 私有 IP 使用新的,然后等待几个小时使这些更改传播,您将在您的 WHM 平台中看到同步的新私有 IP 和 Public IP。