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?
You can use:
As a single command. The && just runs one command, then the other if the first command succeeds. If you are required to use sudo make sure you use it before each command:
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, out-of-band 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.
You can 'restart' one interface by issuing following commands:
After that, you can verify that your new configuration is active
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:
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.
all answers talking about ifup & ifdown are not according to the question. ifup & ifdown just bring the interface up and down only, it doesn't effect the network service. for linux network service doesn't mean interfaces ip setup only.
please check /etc/rc.d/network script for more details.