Ubuntu: Changing your IP number

Sure it doesn’t happen that often, but sometimes you might need to change the IP number of your machine running Ubuntu. Either to configure it with a static IP number on your LAN or temporarily to configure a Wifi router – the latter being my case.

The first shot at changing the ip number, was going to the “System” menu, choosing Administration and Network Tools. It sounded just about right – but it’s wrong. Sure you view settings and some statistics, but it’s all read only.

ubuntu-network-connectionsSo, if you want to change the IP number, go to your top panel (in the right side, you’ll find you network icon. Right click on the icon and choose “Edit Connections”. In the window opening, you’ll have access to changing the ip number – to manual configuration, DHCP with ip number only or (as is default) full DHCP configuration.

Choosing “Automatic (DHCP) addresses only” allows you to get an automatic IP, but use openDNS’ DNS-servers – should you prefer them over the DNS servers provided by your ISP.

IP address conversion with Perl

With Perl you can do many interesting transformations of IP-numbers. Below is two small examples allowing conversions from “IP quad” (xxx.xxx.xxx.xxx)
format to a single decimal and back. The decimal format may be more convenient and efficient to store in a database.

  sub ip2dec ($) {
    return unpack N => pack CCCC => split /\./ => shift;

  sub dec2ip ($) {
    return join '.' => map { ($_[0] >> 8*(3-$_)) % 256 } 0 .. 3;

In CPAN you can find many modules aimed at using and manipulating IP-addressees.

Some include Net::IP and IP::Country.