Setting a static IP address in Ubuntu Server

Networking takes care of itself in Windows, and static IPs aren’t very hard. But how do you set a static IP address in Ubuntu Server?

I’ve used Linux regularly for more than ten years. For the majority of that time, I’ve used Ubuntu, although I’ve also dabbled in Fedora (without much success) and CentOS (with marginally more).

I’m generally comfortable with Linux and when I’m not, I usually know where to look. However, if there’s one thing I always seem to have issues with on Linux, it’s networking.

When I first used Ubuntu, it was often a struggle to get any usable networking. After a while, it was just wireless (mainly WPA) which caused an issue. Latterly, the main issue I’ve encountered is networking with virtual machines (and most of those issues have been with VirtualBox – VMware doesn’t seem to encounter the same issues).

If you’re working with a server, you’ll want to set a static IP address. Once working, this makes things much easier than using a dynamic address.

If you use Ubuntu Desktop, you can edit these settings very easily from your control panel, but on Ubuntu Server you’ll need to use the command line.

In Ubuntu, your network settings are stored in /etc/network/interfaces. To edit the file, enter nano /etc/network/interfaces in a command line (or, if you have a different text editor, like vi, use that instead of nano). This will open the file in a text editor. A sample file might look like this (comments removed):

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

So, what does that mean? Well, there are two interfaces. The first is the loopback interface. Leave that be – if you mess with it, things will break. Ubuntu uses that to communicate with itself.

The second is the eth0 interface. This is your network card. You may have more than one; if you have a second, it might be labelled eth1. Your network card have a completely different designation – on my VMware virtual machine, it’s labelled ens33).

The second line in each of those blocks sets those interfaces. The first lines (auto lo and auto eth0) tell Ubuntu to start those interfaces on boot. If eth0 wasn’t started on boot, the machine wouldn’t have any networking outwith the machine, which will cause you problems!

In the example above, and by default, Ubuntu uses DHCP, so the instance will allow your DHCP server (usually your router) to give the machine an IP address and set any other settings with it.

So, how do you set a static IP address? Well, it goes something like this:

auto eth0
iface eth0 inet static
address 192.168.0.10
netmask 255.255.255.0
network 192.168.1.0
gateway 192.168.1.254
dns-nameservers 8.8.8.8 8.8.4.4

Line-by-line, that configuration does the following:

  • Sets Ubuntu to configure the eth0 interface on boot.
  • Sets the interface as a static interface (rather than DHCP).
  • Gives the interface an address (in this case, 192.168.0.10).
  • Sets a 24-bit subnet mask (so the network runs 192.168.0.1 – 192.168.0.255), and the network in the line underneath.
  • Sets the gateway (router) address. The address displayed is the one used by BT routers – others may use 192.168.0.1.
  • Sets the DNS nameservers to use. I’ve used Google nameservers in this example. You only need one for things to work, but it’s better to have at least two. You can mix them too – for better redundancy, you could use one Google namerserver and one OpenDNS nameserver.

A few quick notes:

  • Once set, you need to reboot the server for the changes to take full effect. Stopping and starting the networking interface won’t cut it.
  • If you forget to add the auto eth0 line and networking doesn’t automatically come up on boot, run sudo ifup eth0 That will manually bring up the inferface. Remember to fix your configuration afterwards!
  • If you don’t set your DNS nameservers, you’ll still have network access, but you won’t be able to resolve domain names. Thus, you will be able to ping an IP address would work, but pinging an FQDN would not work. You’ll eventually notice if this doesn’t work, because things like updates will fail.

This should be everything you need to know to set up a static IP address in Ubuntu.

2016-17 NFL Playoffs – Super Bowl

Roger Goodell can’t hide any longer. He has to see the Patriots tonight. The question is, does he have to hand them the Vince Lombardi Trophy?

The end is in sight. Only two teams are left fighting for the Vince Lombardi Trophy. Will it be the Atlanta Falcons, or the New England Patriots, who end up victorious in Houston?

One thing I have learned is that it’s not worth me picking against my predictor. Twice I’ve picked against mt predictor in the playoffs, and twice I’ve made the wrong call.

Picking the Patriots as the winners of the AFC Championship game was relatively easy, but my predictor correctly predicted the Falcons would see off the Green Bay Packers – and they did it very easily. The Packers’ defense couldn’t stop the Falcons’ offense, and the Packers didn’t generate much offense of their own for much of the game.

The Patriots, meanwhile, made mincemeat of the Steelers and were never really tested. I suspect the Falcons, with their ability to generate pressure upfront, and their much more potent offense, will do a better job in the Super Bowl. But will it be enough?

In truth, I don’t really know, but the stats suggest the Patriots are the more likely winners in this contest. Whilst the Falcons generate pressure, the Patriots are good at restricting opponents to field goals, whilst neither offense is easy to stop. It should be a great game.

The Patriots have won 6 out of 7 games against playoff opponents this season, whilst the Falcons have won 4 of 6. Both teams lost to the Seattle Seahawks. On the road, the Patriots were 2 of 2, whereas the Falcons were 1 of 2. The Falcon’s home loss was to the Kansas City Chiefs.

My own view is that it’s easier to see the Patriots putting up 30 points on the Falcons, than the Falcons putting 30 points up on the Patriots. And, whist the Falcons lead the league in points rank, the rank comfortably behind the Patriots on everything else.

For the Super Bowl, as there is no real home and road team, I designed a new predictor, by comparing home and road data for the two teams. I compared the following:

  • Average road scores
  • Average home scores
  • Average allowed road scores
  • Average allowed home scores
  • Comparisons of the above

I won’t bore you with the technical details, but if they’re evenly matched, they should win 6 games each in this table.

BasisRoadHomeR-PredH-PredWinner
NE-RPatriotsFalcons28.516.5Patriots
NE-HFalconsPatriots16.530.5Patriots
ATL-RFalconsPatriots3425Falcons
ALT-HPatriotsFalcons3037Falcons
NE-R-ADJPatriotsFalcons31.4525.9Patriots
NE-H-ADJFalconsPatriots26.530.25Patriots
NE-R-ADJFalconsPatriots32.128.6Falcons
NE-H-ADJPatriotsFalcons36.12529.5625Patriots
Road-OFFPatriotsFalcons28.534Falcons
Home-OFFAtlanta FalconsPatriots3730.5Falcons
Road-DEFFalconsPatriots16.525Patriots
Home-DEFPatriotsFalcons3016.5Patriots

As you can see, the Patriots win 7 times, the Falcons 5. So it’s not a big mismatch at all. What is interesting is margin of victory.

Without adjustment, the Patriots win on average by 13 points, whereas the Falcons win by 8.

If looking only on offense, the Falcons should win, by 6 points. If looking only at defense, the Patriots should win, by 11 points.

When making adjustments for the Super Bowl opposition, the Patriots win on three of the four scenarios. Taking the Falcons’ base averages at home and adjusting for the Patriots’ road averages, the Falcons lose, by 6.56 points. Which is funny, because the Falcons are the designated home team in the Super Bowl, if that matters at all… which I doubt.

Anyway, if you add up all these match-ups you get the grand total. So what does it say…?

It says the Patriots will win 29.54 – 26.84. So let’s call that 30-27.

My pick: Patriots.
Predictor says: Well, it doesn’t predict neutral games, but if the Patriots are the road team, it confidently predicts the Patriots by 5 points. If they’re the home team, it’s less confident, but it still picks the Patriots by 5.

I’m sure Tom Brady would settle for another Super Bowl ring, and picking up the MVP car from Roger Goodell and let Matt Ryan keep his league MVP award.

Roger Goodell? He might not enjoy that so much.