0

I have two CentOS virtual machines on VirtualBox . one of them let's say CentOS-1 holds my Web application code . second is CentOS2 .
I have two network connections between these two servers : Bridged & Host-only .

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

in my php web page when I try to ssh like this :

 exec('ssh -p 22 root@192.168.0.101 2>&1 ',$output);

it's working , but when I'm trying to ssh to the host-only network ip :

 exec('ssh -p 22 root@192.168.1.101 2>&1 ',$output);

I got this as an output :

ssh: connect to host 192.168.1.101 port 22: No route to host

I tried to re-generate public key for 192.168.0.137 and copy it to 192.168.0.101 but it didn't help . I also tried to give privileges to apache user :

on CentOS-2 : sudo -u apache ssh root@192.168.1.137 "pwd"
sudo -u apache ssh root@192.168.0.137 "pwd"

on CentOS-1 :

sudo -u apache ssh root@192.168.1.101 "pwd"     
sudo -u apache ssh root@192.168.0.101 "pwd"

neither of the two ways worked . is there any thing that I has missed ?
The output of 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)       

and output of route :

$ 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       

Thanks in advance .

2 Answers2

0

There are going to be a few things you will need to do.

Asuming that pinging one machine to the other results in the same error, try to run this command. Setting up a route

route

You will most likly not see any rules for that. Assuming you have setup the ip addresses in the correct files centos netowkring info

/etc/sysconfig/network

once both the network and route are setup you should be able to talk together. To test if someone is not sending data back tcpdump is your friend. Tcpdump help

WojonsTech
  • 350
  • 1
  • 10
0

here's the answer :
on 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

on CentOS1 who ssh to this server:

sudo -u apache ssh root@192.168.1.191"pwd"

then apache can ssh to 192.168.1.191 and you can do whatever you want :)