30

I have configured network adapter of guest Ubuntu to work in a bridged mode so I could ssh to it from the host machine.

The problem is that the guest Ubuntu ip address keep changing.

Even though it changes within a very short range 192.168.0.4-10 it is still takes time to configure Putty and other programs each time.

Is there a way to make the guest Ubuntu ip address to be static?

My guest OS has the full GUI.

33

To give static ip address graphically

1.Go to network connections

2.Then edit the connections in the wired settings

3.Add the ip address for the system

Here are the images below

Network Connections

Network-connections![

If you are curious, You can find newly created connection from the above steps as configurations file at /etc/NetworkManager/system-connections

  • 1
    You are the champion. With you answer I managed to configure my Ubuntu and Fedora in a seconds. Though I had to restar the Fedora. – Mitten Aug 29 '13 at 12:17
  • Happy to Help :D – Tarun Aug 29 '13 at 12:18
  • the save button is not enabled. What should be the ip address of DNS servers. – Arun Raja Nov 17 '15 at 11:03
  • This was a temporary solution for me. It worked while I struggled to configure two routers to work together. Then it failed and I had to switch back to automatic DHCP. BTW, the Ziggo/Cisco EPC3925 wireless/cableTV gateway/router is a flaming POS. – Diogenes Dec 9 '15 at 8:38
27

Edit /etc/network/interfaces to reflect something like this:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.X
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.X
dns-nameservers 192.168.0.X

Then do a:

sudo /etc/init.d/networking restart

And that will get you fixed up.

  • @Mitten if this answer solved your question pleas mark it as accepted! – Braiam Aug 29 '13 at 12:38
  • 1
    Correction: /etc/network/interfaces. Also, if the static address is routable (in DNS, instead of e.g. 192.168.x.x), edit /etc/hosts and /etc/hostname to match. – Camille Goudeseune Dec 23 '13 at 18:50
  • How do I do this under Ubuntu 17.04? These instructions don't work for that. I'm happy to use either vi or emacs. – Erik Bennett Aug 16 '17 at 14:49
10

OP posted:

Setting Static IP

sudo nano /etc/network/interfaces #  I use vi instead of nano

When you open up the interfaces doc, you will see something like this:

auto lo eth0
iface lo inet loopback
iface eth0 inet dynamic

You want to change it to incorporate the following:

auto lo eth0
iface lo inet loopback
iface eth0 inet static
        address xxx.xxx.xxx.xxx (enter your ip here)
        netmask xxx.xxx.xxx.xxx (mine was 255.255.255.0)
        gateway xxx.xxx.xxx.xxx (enter gateway ip here,usually the address of the router)

Save your changes and exit.

Then I needed to add some dns info to resolv.conf so I opened up the file like so:

sudo nano /etc/resolv.conf # I use vi instead of nano

Initially this file is empty excluding a warning of "Do not put anything in here it will be overwritten". I added the following information none the less.

This is the format:

nameserver xxx.xxx.xxx.xxx(enter your dns server ip)
nameserver xxx.xxx.xxx.xxx(enter your alt dns server ip)

This is what I entered:

nameserver 8.8.8.8 
nameserver 8.8.4.4

Save your changes and exit.

At this point you can either restart networking:

sudo /etc/init.d/networking restart  

or reboot which is what I did:

sudo reboot

Once I was logged back in I tried the install again of pure-ftpd and all is good:

apt-get install pure-ftpd

I hope this helps someone, I looked around for the fix and just happened upon it by accident.

  • 1
    Community wiki or something? :) – moon.musick Sep 9 '13 at 13:05
1

It seems the interface eth0 was configured before and the address was kept persistently (for some reason) by the kernel.

To clear all addresses from interface eth0 without having to restart network services or bringing the interface up/down :

sudo ip addr flush dev eth0

Then you can use ifup to configure eth0 by reading /etc/network/interfaces file :

sudo ifup eth0

For verbosity :

sudo ifup -v eth0
1

On Ubuntu 18.04 LTS Netplan is available and replaced ifupdown by default. Let's say our interface is ens192. To check whether it's being managed by NetworkManager:

cat /run/NetworkManager/conf.d/netplan.conf

Which could output this:

[keyfile]
# devices managed by networkd
unmanaged-devices+=interface-name:ens192,

Backup the configuration file (your path or file may be different):

cp /etc/netplan/01-netcfg.yaml /etc/netplan/01-netcfg.yaml.ori

Then edit /etc/netplan/01-netcfg.yaml to look something like:

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  ethernets:
    ens192:
      dhcp4: false
      wakeonlan: true
      addresses:
        - 192.168.14.2/24
      gateway4: 192.168.14.1
      nameservers:
        addresses: [8.8.8.8]

Generate the output file with debug for extra details:

sudo netplan --debug generate

We'd like to see:

DEBUG:command generate: running ['/lib/netplan/generate']
** (generate:9991): DEBUG: 18:08:30.447: Processing input file //etc/netplan/01-netcfg.yaml..
** (generate:9991): DEBUG: 18:08:30.447: starting new processing pass
** (generate:9991): DEBUG: 18:08:30.448: ens192: setting default backend to 1
** (generate:9991): DEBUG: 18:08:30.448: Generating output files..
** (generate:9991): DEBUG: 18:08:30.449: NetworkManager: definition ens192 is not for us (backend 1)

We can see the actual configuration with:

cat /run/systemd/network/10-netplan-ens192.network

Let's make it active by:

sudo systemctl restart systemd-networkd

Be prepared to lose the connection if doing this over SSH. Do man netplan for details. There is also a related answer on this site.

0

The only thing that worked for me was:

  • go into modem config (http://192.168.0.1)
  • set up DHCP Reservation Lease: it maps LAN IPs to MAC addresses
  • set the interface to use DHCP (the default, modifiable on NetworkManager at nm-connection-editor)
0

==== Configure static IP on Ubuntu 14.04

in file /etc/network/interfaces

iface eth0 inet static
address 10.193.36.29
netmask 255.255.255.0
gateway 10.193.36.1
dns-nameservers 10.124.31.140  10.213.134.41  10.72.255.100

then:

sudo ifup eth0

need some time to take effect

protected by Community Sep 14 '18 at 4:49

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.