Networking
Only one network manager and GUI interface can be enabled.
Network-Manager is installed by default and works for both wired and
wireless connections, and for both static and dynamic (DHCP-assigned) IP
addresses. In the past, some users have preferred the
Wicd network manager, however, and it can be installed instead.
Network Manager
Network Manager
is the network manager installed by default in (K)Ubuntu. It has a tray
applet that allows you to switch between Internet connections (such as
wireless APs or a wired connection).
- After installation on my system with a wired ethernet
connection and manual settings for /etc/network/interfaces, Network
Manager was disabled by default ("unmanaged") at installation. To
activate Network Manager and allow it to manage networking settings, I
edited a file (following the advice in this thread):
kdesudo kate /etc/NetworkManager/NetworkManager.conf
and changed the following section so that it read
true instead of
false:
[ifupdown]
managed=true
Also, I double checked the /var/lib/NetworkManager/NetworkManager.state file to make sure that Networking was enabled:
[main]
NetworkingEnabled=true
I then restarted Network Manager:
sudo service network-manager restart
- When using Network Manager to manage the settings, the default
setting is to obtain an IP address from the DHCP server on the network.
However, I customised the Wired Connection to accept my static IP
address as a "manual" (IPv4) IP address and set my custom DNS servers (I
don't use the DNS servers of my ISP for security reasons) and a random
MAC address (which I change periodically to limit tracking).
- Network Manager reliably worked for me on both wired and
wireless connections. When installing on a laptop with a wireless
connection, it worked (in DHCP mode) without any additional
configuration. Settings could then be set through the Network Manager
plasma widget on the panel bar, including the ability to manually
configure a static IP address for the wireless connection, as well.
Wicd Network Manager
Wicd Network Manager
is a GTK-dependent networking manager written in Python that can be
used in all variants of (K)Ubuntu. To avoid networking conflicts, Wicd
requires the removal of Network Manager prior to installation.
sudo apt-get remove network-manager network-manager-pptp plasma-widget-networkmanagement network-manager-kde
sudo reboot
sudo apt-get install wicd
Note: You must have a wired connection in order to install Wicd.
Either install it prior to removing Network Manager or be sure the
/etc/network/interfaces configuration file is properly configured
manually so the default network interface allows you to access the
Internet through a wired connection:
kdesudo kate /etc/network/interfaces
and remove the
#NetworkManager# comments, if present and makes sure the file contents resemble:
# The loopback network interface
auto lo
iface lo inet loopback
#
# The primary network interface
auto eth0
iface eth0 inet dhcp
Then restart networking:
sudo /etc/init.d/networking restart
This restores the default networking, and then Wicd can be installed.
Once Wicd is installed, the connection settings can be changed through
Wicd.
Set a static IP address
- Precise Pangolin (12.04 LTS) is the first version of (K)Ubuntu
in which I have been able to get Network Manager to accept my static IP
address settings (for both wired and wireless connections).
- Network Manager -> Manage Connections... -> connection -> Edit... -> IPv4 address -> Method: Manual -> IP Address: 192.168.0.111 -> Subnet Mask: 255.255.255.0 -> Gateway: 192.168.0.1 -> OK
- I also add the DNS servers I like to use (I don't use the DNS servers of my ISP for security reasons).
- If you only use only a wired interface, you do not need a
network manager and it can be removed if desired. Doing so requires
configuring the networking settings manually.
- In Precise, Network Manager does not need to be removed
if manual settings are used in /etc/network/interfaces. To allow the
settings to take effect (and the network connection to be "unmanaged" by
Network Manager), edit /etc/NetworkManager/NetworkManager.conf:
sudo kate /etc/NetworkManager/NetworkManager.conf
and change the following section so that it reads
false:
[ifupdown]
managed=false
Then restart Network Manager:
sudo /etc/init.d/network-manager restart
- Edit the /etc/network/interfaces file (use the gedit text editor instead of kate if using Ubuntu instead of Kubuntu):
sudo kate /etc/network/interfaces
- and replace the line (ok if line is missing)
iface eth0 inet dhcp
- with the following lines (using your own LAN settings and desired DNS-nameservers, of course):
auto eth0
iface eth0 inet static
address 192.168.0.35
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
dns-nameservers 8.26.56.26 208.67.222.222 8.20.247.20 208.67.220.220 8.8.8.8 8.8.4.4
-
sudo /etc/init.d/networking restart
- Check to see if your settings are now correct:
ifconfig
- The Wicd network manager also allows a wireless connection to have a static IP.
- In versions prior to Precise Pangolin (12.04 LTS) I was not
able to get Network Manager to accept my static IP address settings. If
you only use only a wired interface, you do not need a network manager
and it can be removed.
- Remove Network Manager (replace network-manager-kde with network-manager if using Ubuntu instead of Kubuntu):
sudo apt-get remove network-manager-kde
sudo reboot
- Edit the /etc/network/interfaces file (use the gedit text editor instead of kate if using Ubuntu instead of Kubuntu):
sudo kate /etc/network/interfaces
- and replace the line (ok if line is missing)
iface eth0 inet dhcp
- with the following lines (using your own LAN settings, of course):
auto eth0
iface eth0 inet static
address 192.168.0.35
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
sudo /etc/init.d/networking restart
- Check to see if your settings are now correct:
ifconfig
Manual configuration from the command-line
3 steps for WEP:
sudo iwconfig eth[N] essid [SSID]
sudo iwconfig eth[N] key restricted s:[PASSWORD]
sudo dhclient
WPA is more complicated:
sudo mkdir /etc/wpa_supplicant
cd /etc/wpa_supplicant
sudo echo network = { > wpa_supplicant.conf
sudo echo ssid="SSID" >> wpa_supplicant.conf
sudo echo key_mgmt=WPA-PSK >> wpa_supplicant.conf
sudo echo psk="PRESHAREDKEY" >> wpa_supplicant.conf
sudo echo } >> wpa_supplicant.conf
cd /etc/network
sudo gedit interfaces
Now add after "auto eth[N] ..." & "iface eth[N] .." :
wpa-driver wext # or whatever driver your network card needs
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Save the file and restart your system.
Internet connection sharing (DHCP server)
In most LANs, an inexpensive router is used to provide
DHCP functions (internet connection sharing).
However, DHCP services can also be provided by a single host computer on your
LAN
if it is directly connected to the Internet. (This is useful, for
instance, if you have a 3G or other wireless EVDO connection to your
computer which you want to share with the other computers on your LAN).
Other client computers on your LAN would then connect to the Internet
through your host computer's Internet connection. The host computer now
essentially performs the DHCP functions of a router.
All "client" computers on the LAN ought to be connected to a
central LAN switch or router. (If using a router, it should have its own
DHCP functions disabled -- you shouldn't have 2 DHCP servers on a LAN
unless you know how to
nest LANs).
They should all be set up to obtain DHCP-assigned dynamic IP addresses
and use the same LAN subnet settings (which in the example below is LAN
IP range
10.0.0.1 - 10.0.0.250 with netmask
255.255.255.0 and gateway
10.0.0.1).
The host computer to be used as the gateway/DHCP server is then
connected (through its own ethernet port) either to one to the ports of
the switch (if used), or to a LAN port of a router (don't use the WAN
port). The host computer then connects directly to the Internet (
WAN) through a second port (which in the example below will be a wireless (wifi) port (wlan0)).
(Note: This setup is easiest if you connect all computers on the
LAN with Ethernet cables to the central switch or router. But also see
using a nested wireless LAN router below.)
(Note: If you want your LAN to use the same subnet as your WAN, see
network interface bridging.)
- Install the DHCP server and firewall programs:
sudo apt-get install dhcp3-server firestarter
- Rename the startup command (through a symbolic link) for the
DHCP server. This is required or Firestarter will not know where to find
it:
sudo ln -sf /etc/init.d/dhcp3-server /etc/init.d/dhcpd
- Edit the DHCP server configuration file:
sudo nano -w /etc/default/dhcp3-server
-
- Change the line
INTERFACES=""
-
- to
INTERFACES="eth0"
sudo dhcpd restart
- Right click on Network-Manager -> Edit Connections... -> Wired -> Add
- -> Connection name: Shared internet connection
- -> IPv4 Settings -> Method: Manual -> Add
- -> Address: 10.0.0.1 -> Netmask: 255.255.255.0 -> Gateway: 0.0.0.0
- -> Available to all users: [x]
- Attach the ethernet cable to (eth0).
- Network-Manager -> Wired Networks -> Shared internet connection
- Adjust your firewall to allow the internet connection sharing. Start Firestarter:
sudo firestarter
- Tell the firewall which port is your direct Internet Connection:
Firestarter -> Preferences -> Firewall -> Network Settings ->
Internet connected network device: (wlan0)
- -> IP address is assigned by DHCP: [x]
- Tell the firewall which port is for the LAN, and specify the details for the LAN:
Firestarter -> Preferences -> Firewall -> Network Settings ->
Local network connected device: (eth0)
- -> Enable internet connection sharing: [x]
- -> Enable DHCP for the local network: [x]
- -> DHCP server details -> Create new DHCP configuration -> Lowest IP address to assign: 10.0.0.2
- -> Highest IP address to assign: 10.0.0.250 -> Name server: <dynamic>
- Note: Use your own desired LAN settings (internal DHCP-assigned dynamic IP address range), of course. In this example I don't use the full IP range 10.0.0.2 - 10.0.0.255 for dynamic IP addresses because I want to reserve some LAN addresses (10.0.0.251 - 10.0.0.255) to be used as static IP addresses).
- If you wish to use this setup all the time, make the "Shared internet connection" profile your default connection profile in Network Manager.
Using a nested wireless LAN router
Many users will already have an established LAN that uses an existing
wireless router and has client computers that are setup to connect
wirelessly to the router. Here's how to maintain this setup and still
use the internet connection sharing method of a single host computer as
described above. This method is known as
nested LANs. The
wireless router will serve as a nested LAN for its wireless clients
(only), but in turn will appear as a single device to the main LAN. The
two LANs must have different IP ranges. For example, the main LAN may
have an IP range
10.0.0.1 - 10.0.0.255 (with netmask
255.255.255.0), as in the above example. The router's nested wireless LAN must then use a different IP range (for example
192.168.0.1 - 192.168.0.255 with netmask
255.255.255.0).
- Do not use your wireless router's WAN (Internet) port.
- Connect the host computer (to be used as your main LAN
gateway/router) to a LAN port (not the WAN/Internet port) of the
wireless LAN router.
- Configure your wireless router's LAN so that it appears to be a single device to the main LAN:
- Setup your wireless router so that the Internet
Connection type is "Static IP" (often in the "Internet Setup" section).
Configure the settings so that its "Internet IP address" is within the
static IP address range of your main LAN (e.g. 10.0.0.254), and make sure the subnet mask matches the one you chose for your main LAN (e.g. 255.255.255.0). The gateway setting should be set to match the IP address of your host computer of the main LAN (e.g. 10.0.0.1
in the example of the preceding section). Now the wireless router will
appear to the host computer as just another device on the main LAN.
- If your wireless LAN is already functioning, you probably
don't have to change any settings, but double-check to make sure the
schema are compatible. Configure the wireless router's settings for the
nested wireless LAN. This is done by enabling the router's DHCP server
functions (in "Network Setup" or some similar configuration section of
the router). The router ought to have as its own wireless LAN gateway
address a "local IP address" (or "LAN IP address") of 192.168.0.1
(for the IP address range used in this example), and a "starting IP
address" (for the DHCP-assigned dynamic IP address range to be used for
the wireless clients) to be 192.168.0.2 or greater. (Some routers ask you to specify the entire range (such as 192.168.0.2 - 192.168.0.255.)
- Make sure all your wireless client computers are set to obtain
their DHCP-assigned dynamic IP addresses from the wireless router
(gateway IP 192.168.0.1) instead of from the main LAN gateway.
- Now all communications from the wireless client computers will
be routed to the wireless LAN router first, which will then in turn
route them to the host computer (which is acting as the main LAN
gateway/router), which will then in turn route them to the Internet
(WAN).
- Note: The host computer for the main LAN must have a static IP address (e.g. 10.0.0.1
as in the example of the preceding section) and it must match the
gateway IP address configured in the wireless LAN router settings.
Network Interfaces Bridging
- Install bridge-utils to be able to create network bridges:
sudo apt-get install bridge-utils
- Edit /etc/network/interfaces:
sudo nano /etc/network/interfaces
The interfaces file should look like this after editing it:
auto eth0
iface eth0 inet manual
#
auto br0
iface br0 inet dhcp
#
bridge_ports eth0 wlan0
#
# The loopback network interface
auto lo
iface lo inet loopback
sudo /etc/init.d/networking restart
Using Dynamic IP addresses for a webserver
Normally, domain name servers (DNS) that are used publicly on the
Internet match a web server's URL name with the IP address of the
server's host computer. If your computer has a
static IP address, then you can publish your own web server's URL as belonging to the static, unchanging IP address of your computer.
However, if your IP address is
dynamic
(always changing) because you use an ISP (Internet Service Provider)
that constantly changes your IP address (using DHCP), then you will need
a Dynamic DNS service to constantly keep track of your dynamically
changing IP address and match it to of your web server's URL.
Fortunately, there are a few Dynamic DNS services that will do this for
you, either for a small fee or even for free. For more info, see
this Ubuntu Community help article.
For specific tips on setting up Dynamic DNS, see
this article.