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

In RHEL, instead of using service network restart command, how can i restart a particular network interface, lets say "eth1", with only one command.

"Only one command" because that is the only interface where my ssh is working on also. So if i'm about to use: ifdown and then ifup, i will never be able to hit the ifup command as my ssh has been terminated once after ifdown eth1 command.

So there should be a single command which allows me to altogether bring down and then bring up the interface which is serving my current ssh connection. So i do not need to worry about connection totally lost to my server.

Any idea please?

share|improve this question

3 Answers 3

up vote 11 down vote accepted

You can use:

ifdown eth1 ; ifup eth1

As a single command. The ';' just runs one command, then the other.

As long as your interface is configured to have the neccessary IP and route to match the current configuration, your ssh connection won't drop.

If you're worried about using it on a production server that you don't have another method of access to, that's understandable. Though the command does exactly what you want, it's very easy to have a configuration error that is only noticed after running this command. If you don't have an alternate method of access (for example, console, or SSHD running on another interface), it's safest not to do this.

I use this technique often to perform a 'restart' of the interface, but I generally have a backup method of access available just in case when I do it.

share|improve this answer
    
this plus OOB management FTW –  dmourati Mar 20 '13 at 7:36
    
Might I suggest ifdown eth1 && ifup eth1, this way ifup doesn't run unless ifdown was successful, whereas with a ; ifup will run regardless of how ifdown returned. –  zamnuts 10 hours ago

You can 'restart' one interface by issuing following commands:

# ifdown eth1
# ifup eth1

After that, you can verify that your new configuration is active

# ip a
share|improve this answer
    
Sorry but i need .. "Only one command" because that is the only interface where my ssh is working on also. So if i'm about to use: ifdown and then ifup, i will never be able to hit the ifup command as my ssh has been terminated once after ifdown eth1 command. So there should be a single command which i can bring down and then bring up the interface which is serving my current ssh connection. So i do not need to worry about connection lost to my server. –  夏期劇場 Mar 20 '13 at 6:18
    
You could make them a shell script and run that, your ssh-session should not get terminated, even though there will be short network blackout. Other option is to run that script inside of screen-session, where it will be executed to the end, even if your ssh-session would fail. –  jerQ Mar 20 '13 at 6:19
    
will this help? ifdown eth1 ; ifup eth1 ? –  夏期劇場 Mar 20 '13 at 6:21

Are you trying to change the IP address (or any interface parameter for that matter) of an interface on a remote machine? If the answer is yes, then you can try one of the following:

A cool method is by using the screen utility to create a session by just typing 'screen'. Once you restart the network service and your SSH connection drops, use screen -ls to check that the session is still active (but detached) and screen -r to resume the detached session. This will work in case there is no error in your interface configuration file, i.e. the network service is restarted successfully.

You can also use the following trick:

$ cp -v current_conf_file current_conf_file.bak
$ echo "mv current_conf_file.bak current_conf_file && service network restart" | at now+10min

And proceed with editing your interface configuration file and restarting the network service. In case of a mistake, you just have to wait 10 minutes, in order for the previous configuration to be reapplied and the network service to be restarted.

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.