I am hosting a Ubuntu server, and am trying to learn better how to administer and secure it, using resources available on the net and in popular books. To do that, I installed the free VMWare Server, created a virtual machine that is aware of my local area network, and installed an image of Ubuntu Server on it. The host machine is a desktop, also running Ubuntu.
The first problem I ran into is that VMWare sets virtual machines to obtain their IP addresses from a DHCP server. Which means that every time the host server is rebooted (power outages, shut down due to travel, or the occasional crash that takes place on the desktop (much less on a server), the IP address changes and the server is no longer accessible on the older IP address. In general, a server is better off with a static IP address, so my first assignment is to change the IP address to a static address, and assign it.
But how do I do it without a GUI? Here Google is your friend. A quick search for static ip ubuntu server vmware provides dozens of helpful web pages.
Apparently, there is a relevant file, which can be edited to accomplish this feat. It is also possible to use the ifconfig command, but I’d edit files rather than use commands any day of the week. The first one is /etc/network/interfaces, which you can view with the less command, and edit with vim, nano, pico, or other text editors.
If your machine is using dhcp to obtain an IP address, the relevant entry in the file would be (where eth0 is your first internet card):
auto eth0
iface eth0 inet dhcp
Using the editor, change this entry to (use the su command to edit as root – you need root privileges to edit this file):
iface eth0 inet static
address 192.168.1.3
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
The first line changes the way an IP is obtained from dhcp to static, and the following set the address and network settings for the ethernet card. Here the network is 192.168.1.N and the machine’s new IP address will be 192.168.1.3; Make sure it does not conflict with other computers on the home/office network.
After making the changes, networking has to be restarted, using the command, sudo /etc/init.d/networking restart, and checked using the command ifconfig, which should display the assigned network address.
The ping command can then be used to ping the gateway, another computer on the network, or even an external computer from the net.