update /etc/hosts
I setup 4 virtualbox vms which have dynamic ip (my env uses dhcp ).
Now I need to ssh to each vm so when ip is changed, I have to check vm's ip and update /etc/hosts so that when next time ssh user@vm_host would work. So I wrote a simple script and want to update /etc/hosts once vms are started up. But it seems the content of /etc/hosts won't be changed after executing the script, and the console shows '127.0.0.1: not found' What may go wrong? And hot to fix it? Below is the script content. Code:
for i in 1 2 3 4 /etc/hosts looks as below: Code:
127.0.0.1 localhost |
I know this is not specifically what you have asked, however, why don't you just configure the individual machines with a static ip? There are only 4, it is not like there are thousands.
|
I share network environment with other people in the building, so ip would be conflict if using the same one.
Quote:
|
Just choose a different subnet for the VMs and you should be fine.
|
You can also create a seperate subnet as the previous post said, or if you have control over the DHCP server or know what the address pool range is, assign 4 ip addresses that is not in the shared pool. That way there won't be conflicts either.
|
If you are getting the IPs OK, this is a straight sed question.
The sed command will not work as intended because the single quotes prevent substitution of the "$i"s. Change from single to double quotes and see if that works. BTW the first part doesn't work for me: Code:
c@CW8:~/d$ VBoxManage guestproperty get CW8vDS "/VirtualBox/GuestInfo/Net/0/V4/IP" |
Quote:
Code:
#!/bin/sh |
All times are GMT -5. The time now is 02:46 PM. |