Restart network without reboot ?

dteske at FreeBSD.org dteske at FreeBSD.org
Mon Feb 10 16:31:04 UTC 2014



> -----Original Message-----
> From: Vladislav Prodan [mailto:universite at ukr.net]
> Sent: Saturday, February 8, 2014 5:01 AM
> To: Darren Pilgrim
> Cc: Erich Dollansky; questions at freebsd.org
> Subject: Re[2]: Restart network without reboot ?
> 
> > On 2/7/2014 6:43 PM, Vladislav Prodan wrote:
> > >> "Erich Dollansky" <erichsfreebsdlist at alogt.com> wrote:
> > >> On Sat, 08 Feb 2014 03:31:08 +0200 Vladislav Prodan
> > >> <universite at ukr.net> wrote:
> > >>>
> > >>> # service netif restart && service routing restart Stopping
> > >>> dhclient. Waiting for PIDS: 672.
> > >>>
> > >>> And disconnect via ssh :(
> > >>
> > >> as expected.
> > >>
> > >> What is your problem?
> > >
> > > What there are other ways to restart the network without breaking
> > > the current ssh session?
> >
> > You can't. The connection state is going to get reset. You can,
> > however, run the service commands in a screen or tmux session to
> > prevent the connection reset from disrupting the shell running the
service
> commands.
> >
> > You should also add ";service sshd restart" to the end of the command
> > to make sure sshd comes back up if died when networking bounced.
> >
> 
> Thank you all for your clever ideas and tips.
> 
> help:
> service netif restart ; dhclient em0 ; dhclient em1
> 
> 
[Devin Teske] 

What we do at $work for boxes that need an IP change remotely via SSH...

1. Put that code into a script... for example...

$ cat << EOF > /tmp/do_it_now.sh
#!/bin/sh
service netif restart
dhclient em0
dhclient em1
EOF

Then add a line to your /etc/crontab that will fire in the next 1-2
minutes...

sh -c 'echo "$((($(date +%M)+2)%60)) $(date +%H) * * * root sh
/tmp/do_it_now.sh" >> /etc/crontab'

NB: That's a single command to be entered on a single line

Then just wait a minute or two, you'll get kicked out, start a ping, and
when
it starts responding on the new IP address (hopefully you know what this is)
you can log in on the new address.

Of course, the next thing you should do is to edit /etc/crontab to remove
the
entry else the same time tomorrow it will reset your network.

Lastly, remove the /tmp/do_it_now.sh script.
-- 
Devin

_____________
The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you.


More information about the freebsd-questions mailing list