I have a few Ubuntu server boxes set up on ESX, and I changed the IP addresses via SSH. The moment I changed it, it dropped me off of SSH (as expected).
After a restart it works 100% as expected and I can SSH in on the new IP.
However, as much as this works and I know it is a solution, I am trying to learn Linux and would like to restart/bind SSH to the new IP without restarting.
I have attempted /etc/init.d/ssh restart
(and stop
then start
), and services ssh restart
(and stop
then start
), but, nothing seems to work.
However, the weird thing is that from my other server (running on the same ESX box) I can SSH in on the new IP, but, I just can't seem to SSH in from anywhere else until the box is restarted.
I can't work out what I am doing wrong.
Has anyone seen this or can they offer any advice?
(if it changes anything, the IPs I was moving from/to are all internet/public directly routed IPs)
I have a hunch this is related to ARP, which can be sometimes funky with virtual machines. From another virtual server on the same box, you can connect, as you're not going through the switch.
To test this, first try clearing the ARP tables on the machine from which you're trying (and failing) to connect:
If that doesn't help, try resetting the ARP table on your switch (one easy way to do it: reset the switch :)
It the configuration of openssh-server is untouched (the default one) then you don't even need to restart ssh in order for him to listen onto the new IP you set.
Your trouble is likely to be the way you change your IP.
I don't know how you do it so I'll cover all cases
I advise you to not use the GUI : network-manager. It's very poor in functionality and does not fit your need for remote changes. (any graphical interface is quite a bad idea on a server because it adds you potential risks and consume constantly resources for 5 minutes of use)
My advice would be to edit /etc/network/interface
See this help : Network Configuration on Ubuntu 11.10 and most importantly the "IP Addressing" part.
Be sure to not use the hotplug statement witch can leads you in trouble.
changing the IP with ifconfig is a bad idea : it's temporary and it do directly the change so you can't set/unset other network settings
Now the real trick :
(ifconfig aside) : The very act of changing the same IP of your SSH session is in fact two procedures for Ubuntu : Stop the interface and then Start the interface.
So what you use is a script, and when the interface stops your ssh session closed .... and so your script. So your interface never start again.
in order to avoid your script being closed you must the script in background :
It'll send your script to the background and so it'll not be closed when your ssh session close.
You'll loose then your ssh session, but you'll be able to connect again into your server without restarting. (leave it a little time if you are defining a new dhcp ip or if it's wifi)
If this doesn't work for you please give us more details on how you proceed.
Best regards.
When you change your ip address, do you add the default route? Seems to me like because you didn't add the default route, the computer is unable to access, and be accessed from, outside. Lets say you changed your ip address so, as root:
After you do this, you need to add the default route, which, if not done, won't let your server connect to the internet. To be accessible outside, the default route needs to be added:
Hope that solves the problem.
Do your
iptables
rules prohibit any incoming connections to any IP other than your own? It might be updated automatically on reboot - it would be unusual I think, I've never seen it done, but it would explain this behaviour.Try
and see if any of the rules in there look responsible for filtering incoming connections to the IP your machine has(had).
Check you sshd_config in /etc/ssh
and check if there is a listen adres in config for example:
ListenAddress 212.72.224.8
If thats there change to right adres and do a service ssh restart