1

I have to simulate unplugged network cable for testing issue to all applications we are developing in my company .
I have about 6 virtual machines Cent-OS on a virtual box .
from a php web page , I have to choose a server and stop its network and then start it again . of course I'm using ssh for remote connection to other servers .
and I if I stopped the eth0 (main network) on a server . I won't be able to reach it again with ssh . so I had to find another way to perform this .
I made another network connection (Host-only) between servers via virtualbox with the help of this tutorial , then I logged into one of the servers to configure IP for this new network with these two commands :

 sudo ifconfig eth1 192.168.1.101 up 

also

sudo ifconfig eth1 inet 192.168.1.101 broadcast 192.168.1.255 netmask 255.255.255.0 up   

but when I'm trying to ssh this via php :

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

I get this output :

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

I don't know what I have missed ?

Edit : This is what I get when I run route

$ route -n                                                                                                        
Kernel IP routing table                                                                                                               
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface                                                         
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1                                                          
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0                                                          
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0                                                          
0.0.0.0         192.168.0.204   0.0.0.0         UG    0      0        0 eth0       
MadHatter
  • 79,770
  • 20
  • 184
  • 232
  • Are you sure you typed it correctly, you have a comma in your IP address instead of a period. – David Houde Apr 11 '13 at 08:13
  • I've edited my question . – Nancy Smith Apr 11 '13 at 08:25
  • The question changes, from ping local IP to ssh to remote IP. Diagnostic steps: [from host] ping 127.0.0.1 OK? ping 192.168.1.101 OK? ping 192.168.1.1 (default route) OK? ping from other host. Also, what is the IP of eth0? There may be conflict in IP, netmask, or default gateway. – David Houde Apr 11 '13 at 08:29
  • well , sorry for this conflict :$ . I tried your first and second ping and they're working correctly . yet last one is giving me `$ ping 192.168.1.1 PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data. From 192.168.1.101 icmp_seq=2 Destination Host Unreachable` – Nancy Smith Apr 11 '13 at 08:34
  • ip of eth0 is : 192.168.0.101 . this is the first time I deal with network connections . forgive my silly mistakes . – Nancy Smith Apr 11 '13 at 08:35
  • ok that just kinda verifies your network stack is working and the interface is configured up. Next, can you give the IP of eth0 including network mask? also the output of the 'route' command may help. – David Houde Apr 11 '13 at 08:35
  • eth0 configurations with ifconfig :`inet addr:192.168.0.101 Bcast:192.168.0.255 Mask:255.255.255.0`
    I will add route output to question can't put it here (so long )
    – Nancy Smith Apr 11 '13 at 08:39
  • Just to make sure, you are trying to SSH from another virtual machine on the same host, correct? – David Houde Apr 11 '13 at 08:44
  • yep , I'm also logged in to another machine '192.168.0.137' and I'm trying to reach 192.168.1.101 with `ssh 192.168.1.101` but I'm getting `ssh: connect to host 192.168.1.101 port 22: No route to host` . P.S : `ssh 192.168.0.101` is working correctly . – Nancy Smith Apr 11 '13 at 08:48
  • That other server will have to have a second "Host-Only" interface on the 192.168.1.x network also, as the 192.168.0.x and 192.168.1.x networks are not routed together (think of 192.168.1.x as a management LAN) – David Houde Apr 11 '13 at 08:50
  • you are right I'm trying to make eth1 up on 137 but I just have root privileges on this server via apache service . still refusing to gets ip with this command `exec(' sudo ifconfig eth1 inet 192.168.1.137 broadcast 192.168.1.255 netmask 255.255.255.0 up');` – Nancy Smith Apr 11 '13 at 08:53

1 Answers1

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 :)

 $ip_eth1= '192.168.1.191';
 $port='22';
 exec('ssh -p '.$port.' root@'.$ip_eth1.' "ip link set dev eth0 up";');
 exec('ssh -p '.$port.' root@'.$ip_eth1.' "ip link set dev eth0 down";');