Linux/Networking Services
From charlesreid1
Overview
This page will cover a couple of key aspects of networking services on Linux:
- ip address schema
- dhcp server
- dns server
- ntp server
IP Schema
First principle: keep schema easy to change
What types of machines are you providing addresses to? Servers/workstations/printers, but now also phones, conference systems, tablets. many devices also have multiple network interfaces. a default network of 24 bits, 254 usable ip addresses, is not large enough for many situations.
multiple subnets would help to create individual networks for groups of devices (types of services). example: have servers on one subnet, printers on antoher, workstations on yet another.
the broadcast domain should also be limited. With a one-size-fits-all 24 bit network, you have a single subnet, and a single broadcast domain. Every device can communicate with every other device, with no need for routing. However, on large networks, breaking down the broadcast domain can help ensure performance. Organizing sub domains for different services keep those services from being overwhelmed.
To plan IP schema, use the ipcalc utility. This can help you understand the number of IP addresses that will be available for a given schema.
$ apt-get install ipcalc
You give it arguments of the network you are thinking about using:
$ ipcalc 10.10.96.0/22
ipcalc shows Hosts/Net, which is the number of allowable IP addresses that this network would give us.
The utility also shows the subnet mask that would be required, which is 255.255.252.0.
ipv4 vs ipv6
insert obligatory reference to number of IP addresses running out...
ipv6 needs to be ushered in.
HOWEVER, for small, internal networks, there is absolutely no need to complicate your life with ipv6. The namespace for ipv4 running out will only affect the wider internet, and not local nor private network IP spaces.
Unless you are a networking company. Or studying for a certification.
dhcp server
now that we have used ipcalc to decide on a network layout (ip schema, number of addresses, number of bits, subnet mask, etc.), put it into action.
set up dhcp server to configure and serve up IPv4 addresses to machines that want one.
Use the isc-dhcp-server:
$ apt-get install isc-dhcp-server
Now configure the dhcp server by editing its configuration file, located at /etc/dhcp/dhcp.conf
If you have a sample dhcp.conf file present, it will be pretty extensive. Or, it might be totally empty. Here is a sample:
default-lease-time 86400;
max-lease-time 86400;
option subnet-mask 255.255.252.0;
option broadcast-address 10.10.99.255;
option domain-name "local.lan";
authoritative;
subnet 10.10.96.0 netmask 255.255.252.0 {
range 10.10.99.100 10.10.99.254;
option routers 10.10.96.1;
option domain-name-servers 10.10.96.1;
}
To go through that a bit slower:
the default lease time and max lease time set the lease times of ip addresses.
The subnet mask and broadcast address options specify what subnet mask the clients will be given, and what broadcast address they'll use.
The subnet mask identifies the network that each connecting node will be a part of. The clients check their IP information after being provided an address. The subnet mask identified here should be shown.
The broadcast address is the address on which all nodes within this subnet are able to receive packets.
The domain-name option applies the domain name to the hostnames of each node that connects to the DHCP server. The authoritative option specifies that this DHCP server should be the primary DHCP server for this subnet.
The following lines about the subnet range, routers, and domain name servers:
subnet 10.10.96.0 netmask 255.255.252.0 {
range 10.10.99.1 10.10.99.254;
option routers 10.10.96.1;
option domain-name-servers 10.10.96.1;
}
these identify network address for the subnet, the subnet mask, the range of IP addresses that will be issued, the default gateway, and the DNS server.
This example shows that the first DHCP-issued address will be at 10.10.99.100 and it will end at 10.10.99.254.
This cuts out a really large number of possible IP addresses. The range we have specified, 10.10.96.0/22, covers the following subnets:
10.10.96.0 10.10.97.0 10.10.98.0 10.10.99.0
so in fact we could hand out IP addresses starting at 10.10.96.1, rather than 10.10.99.100.
Once you have edited this file, you will restart the daemon.
$ systemctl restart isc-dhcp-server
an easier example
This example is easier, as it only configures a network like 10.10.10.0/24 - a 24 bit network:
default-lease-time 86400;
max-lease-time 86400;
option subnet-mask 255.255.255.0;
option broadcast-address 10.10.10.255;
option domain-name "local.lan";
authoritative;
subnet 10.10.10.0 netmask 255.255.255.0 {
range 10.10.10.10 10.10.10.254;
option routers 10.10.96.1;
option domain-name-servers 10.10.96.1;
}
This sets the dhcp range to start at 10.10.10.10 and end at 10.10.10.254. This gives 9 IP addresses that will never be assigned - which is useful if you need to assign static IP addresses to any machines.
Static IP Addresses
To configure the DHCP server to hand out a static IP address lease, place a reservation at the end of /etc/dhcp/dhcpd.conf:
host miami {
hardware ethernet AA:BB:AB:BA:DE:AD:BE:EF
fixed-address 10.10.97.4
}
This will give the host miami with the mac address specified the fixed IP address of 10.10.97.4.
Restarting DHCP Server
To restart the DHCP server once you have made changes:
$ systemctl restart isc-dhcp-server
DNS Server
DNS stands for domain name system - it turns IP addresses into human-readable host names.
DNS is useful for the wider internet, obviously, but is also useful on a small network. DNS is useful for more than a handful of networked computers.
Installing/Starting
On Debian, use bind9 (BIND = Berkeley Internet Name Domain). This is the most popular name server around. Once you install it, Debian should boot it up for you and configure the daemon.
First, install it:
$ apt-get install bind9
Check that it is running:
$ systemctl status bind9
● bind9.service - BIND Domain Name Server
Loaded: loaded (/lib/systemd/system/bind9.service; disabled)
Drop-In: /run/systemd/generator/bind9.service.d
└─50-insserv.conf-$named.conf
Active: active (running) since Mon 2016-03-14 15:00:06 PDT; 18s ago
Docs: man:named(8)
Main PID: 16356 (named)
CGroup: /system.slice/bind9.service
└─16356 /usr/sbin/named -f -u bind
Mar 14 15:00:06 basilisk named[16356]: automatic empty zone: 8.B.D.0.1.0.0.2.IP6.ARPA
Mar 14 15:00:06 basilisk named[16356]: command channel listening on 127.0.0.1#953
Mar 14 15:00:06 basilisk named[16356]: couldn't add command channel ::1#953: address not available
Mar 14 15:00:06 basilisk named[16356]: managed-keys-zone: loaded serial 0
Mar 14 15:00:06 basilisk named[16356]: zone 0.in-addr.arpa/IN: loaded serial 1
Mar 14 15:00:06 basilisk named[16356]: zone 127.in-addr.arpa/IN: loaded serial 1
Mar 14 15:00:06 basilisk named[16356]: zone 255.in-addr.arpa/IN: loaded serial 1
Mar 14 15:00:06 basilisk named[16356]: zone localhost/IN: loaded serial 2
Mar 14 15:00:06 basilisk named[16356]: all zones loaded
Mar 14 15:00:06 basilisk named[16356]: running
Until the DNS server is configured, it won't be doing anything for us.
Configuring DNS
The configuration file for BIND is located in /etc/bind/named.conf.
If the file has text in it already, back it up and clear it out. Now what we'll do is include two additional configuration files, to make our lives easier:
include "/etc/bind/named.conf.options" include "/etc/bind/named.conf.local"
Note that we can put those files wherever we want, and create our own layout of configuration files.
Configure DNS Forwarding
We will start by editing the BIND configuration options:
$ vim /etc/bind/named.conf.options
Edit this file and add the following contents:
options {
forwarders {
8.8.8.8; 8.8.4.4;
};
};
What we are doing here is to create instructions for where to forward DNS requests, if it cannot find what it is looking for. (Note that this is usually done by default, but doing it this way allows us to specify which DNS servers to use.) These two (8.8.8.8 or 8.8.4.4) are both name servers from Google.
Local DNS Configuration
Now we can set up the configuration for our local network in the other configuration file. Edit this file:
$ vim /etc/bind/named.conf.local
Now add the following contents:
zone "local.lan" IN {
type master; file "/etc/bind/net.local.lan";
};
zone "96.10.10.in-appr.arpa" {
type master; notify no; file "etc/bind/revp.10.10.96";
};
zone "97.10.10.in-appr.arpa" {
type master; notify no; file "etc/bind/revp.10.10.97";
};
zone "98.10.10.in-appr.arpa" {
type master; notify no; file "etc/bind/revp.10.10.98";
};
zone "99.10.10.in-appr.arpa" {
type master; notify no; file "etc/bind/revp.10.10.99";
};
Here is an explanation of the pieces:
- The first line defines our local domain name. We picked the very boring name of "local.lan"
- This block calls out another file, "/etc/bind/net.local.lan"
- The remaining four blocks create configurations for reverse lookups on the four subnets we are creating. If you only have one subnet on your network, you will only include one block for the one subnet.
- Each subnet has its own reverse-lookup file where we can configure things, each being stored in
/etc/bind.
DNS Records
Now let's look at the actual DNS records (in the reverse-lookup files listed in the code above).
Starting with /etc/bind/net.local.lan:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; dns zone for for local.lan network ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; $TTL 1D @ IN SOA local.lan. administrator.local.lan. ( 201507261 ; serial 8H ; refresh 4H ; retry 4W ; expire 1D ) ; minimum IN A 10.10.96.1 ; @ IN NS hermes.local.lan. ceres IN A 10.10.98.1 euphoria IN A 10.10.97.4 galaxy IN A 10.10.96.4 hermes IN A 10.10.96.1 puppet CNAME galaxy ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; end dns zone for for local.lan network ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Going through this line by line:
- TTL is time to live, set to 1 day - this is how long DNS records are cached (important with multiple DNS servers or dynamic IP addresses)
- SOA is start of authority, which defines which comptuer has DNS authority on this local network. The
administrator.local.lanis an email address. - 201507261 is the serial number. if you change a zone file in bind, you should change this serial number. It is the first thing the daemon reads and it is how the daemon knows if the DNS records have been changed.
Related
| linux networking all the pages for linux networking
Diagnosing network interfaces: Linux/Network Interfaces Connecting to nodes with ssh: Linux/SSH Bridging networks with ssh tunnels: Linux/SSH Linux file server nfs/smb/sshfs: Linux/File Server Samba on linux: Linux/Samba Automounting network shares on linux: Linux/Automount Network Shares Monitoring system resources: Linux/System Monitoring Linux systemd: Linux/Systemd
IP Schema (ipcalc): Linux/IP Schema DHCP Server: Linux/DHCP DNS Server: Linux/DNS NTP Server: Linux/NTP
|