How to configure static ip in Ubuntu running on virtual box?

I am using Ubuntu on VirtualBox in Dell Laptop and wanted to know how I can configure the static IP in Ubuntu so that I can browse internet on Ubuntu and also use putty.

I am using data card for internet.

Currently in /etc/network/interfaces the settings is as follows:

iface eth0 inet dhcp

Solution 1:

Find your actual network configuration by typing

ifconfig

You should see something similar to

eth0 Link encap Ethernet HWaddr 00:00:00:00:00:00
inet addr:192.168.1.10 Bcast 192.168.1.255 Mask:255.255.255.0

Edit the networking config file by typing

sudo nano /etc/network/interfaces

Inside it find the line

auto eth0
iface eth0 inet dhcp

and change it to

auto eth0
iface eth0 inet static
address 192.168.1.115
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 192.168.1.1

The actual change may need to be modified to something more specific for you. IE if you're routers IP is 10.0.0.1 then your gateway and dns-nameservers would need to be configured accordingly. I set the address to 192.168.1.115 because the odds of you getting enough connections to reach that IP and have any conflict from DHCP are slim to none. Let me know if this works for you. Good luck.

--Also. Your network adapter should be bridged.--

Solution 2:

The easiest method is through network manager:

1- From the top of the screen select the network icon, next to the clock and volume, then click Edit Connections.

2- From the window that opens, go to Wired tab, select your connection (there should be only one connection, if you didn't touch anything). Then click Edit.

3- From the IPv4 Settings tab change Method from Automatic (DHCP) to Manual.

4- Under Addresses feild, click on Add.

5- Enter your desired IP address and subnet mask and click Save, you can also enter an optional DNS server here.