我在 VirtualBox 上有两个 CentOS 虚拟机。其中之一假设 CentOS-1 保存着我的 Web 应用程序代码。其次是CentOS2。我在这两台服务器之间有两个网络连接:桥接和仅主机。
CentOS-1 : for Bridged connection the ip is : 192.168.0.137
for Host-only connection the ip is : 192.168.1.137
CentOS-2 : for Bridged connection the ip is : 192.168.0.101
for Host-only connection the ip is : 192.168.1.101
当我尝试像这样进行 ssh 时,在我的 php 网页中:
exec('ssh -p 22 [email protected] 2>&1 ',$output);
它正在工作,但是当我尝试 ssh 到仅主机网络 ip 时:
exec('ssh -p 22 [email protected] 2>&1 ',$output);
我得到这个作为输出:
ssh: connect to host 192.168.1.101 port 22: No route to host
我尝试重新生成 192.168.0.137 的公钥并将其复制到 192.168.0.101,但没有帮助。我还尝试授予 apache 用户权限:
在 CentOS-2 上:
sudo -u apache ssh [email protected] "pwd"
sudo -u apache ssh [email protected] "pwd"
在 CentOS-1 上:
sudo -u apache ssh [email protected] "pwd"
sudo -u apache ssh [email protected] "pwd"
这两种方法都不起作用。我有什么遗漏的吗?的输出ifconfig -a
:
$ ifconfig -a
eth0 Link encap:Ethernet HWaddr 08:00:27:0B:56:0E
inet addr:192.168.0.101 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe0b:560e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:5652 errors:0 dropped:0 overruns:0 frame:0
TX packets:4886 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:833395 (813.8 KiB) TX bytes:769122 (751.0 KiB)
eth1 Link encap:Ethernet HWaddr 08:00:27:FA:C6:32
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:6315 errors:0 dropped:0 overruns:0 frame:0
TX packets:6315 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:878894 (858.2 KiB) TX bytes:878894 (858.2 KiB)
和路线的输出:
$ sudo ifconfig eth1 inet 192.168.1.101 broadcast 192.168.1.255 netmask 255.255.255.0 up
[sudo] password for safaa:
[safaa@AMeS101 ~]$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 * 255.255.255.0 U 0 0 0 eth1
192.168.0.0 * 255.255.255.0 U 0 0 0 eth0
link-local * 255.255.0.0 U 1002 0 0 eth0
default mbox.kds.local 0.0.0.0 UG 0 0 0 eth0
答案1
答案如下:
在 CentOS1 上:
sudo ifconfig eth1 192.168.1.191 netmask 255.255.255.0 up
sudo touch /etc/sysconfig/network-scripts/ifcfg-eth1
sudo vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE="eth1"
IPADDR=192.168.1.191
NETMASK=255.255.255.0
NETWORK=192.168.1.0
BROADCAST=192.168.1.255
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
然后:
sudo ifup eth1
在 CentOS1 上通过 ssh 连接到该服务器:
sudo -u apache ssh [email protected]"pwd"
然后apache可以ssh到192.168.1.191,你可以做任何你想做的事:)