How to "restart" particular network interface on RHEL?

116,031

Solution 1

You can use:

ifdown eth1 && ifup eth1

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:

sudo ifdown eth1 && sudo ifup eth1

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.

Solution 2

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:
116,031

Related videos on Youtube

夏期劇場
Author by

夏期劇場

SOreadytohelp

Updated on September 18, 2022

Comments

  • 夏期劇場
    夏期劇場 almost 2 years

    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?

  • 夏期劇場
    夏期劇場 over 11 years
    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.
  • jerQ
    jerQ over 11 years
    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.
  • 夏期劇場
    夏期劇場 over 11 years
    will this help? ifdown eth1 ; ifup eth1 ?
  • dmourati
    dmourati over 11 years
    this plus OOB management FTW
  • marshel111
    marshel111 over 9 years
    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.
  • David Gardner
    David Gardner almost 9 years
    @zamnuts Answer now edited to include this :)
  • MadHatter
    MadHatter almost 8 years
    I'm not sure what point you're making. The OP doesn't ask about restarting the network service, but only restarting an individual interface. Moreover, the OP has accepted an answer that explicitly uses the commands you're recommending against. -1 from me.