Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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       
share|improve this question
    
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 8:13
    
I've edited my question . –  Nancy Smith Apr 11 '13 at 8: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 8: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 8: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 8:35

1 Answer 1

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";');
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.