Linux SRV
Linux SRV
Linux SRV
Paul Cobbaut
Linux Servers
Paul Cobbaut
lt-0.5
Publication date Fri 16 May 2014 01:01:35 AM CEST
Abstract
This book is meant to be used in an instructor-led training. For self-study, the intent is to read
this book next to a working Linux computer so you can immediately do every subject, practicing
each command.
This book is aimed at novice Linux system administrators (and might be interesting and useful
for home users that want to know a bit more about their Linux system). However, this book
is not meant as an introduction to Linux desktop applications like text editors, browsers, mail
clients, multimedia or office applications.
More information and free .pdf available at http://linux-training.be .
Feel free to contact the author:
Paul Cobbaut: [email protected], http://www.linkedin.com/in/cobbaut
Contributors to the Linux Training project are:
Serge van Ginderachter: [email protected], build scripts and infrastructure setup
Ywein Van den Brande: [email protected], license and legal sections
Hendrik De Vloed: [email protected], buildheader.pl script
We'd also like to thank our reviewers:
Wouter Verhelst: [email protected], http://grep.be
Geert
Goossens:
geertgoossens
http://www.linkedin.com/in/
Permission is granted to copy, distribute and/or modify this document under the terms of the
GNU Free Documentation License, Version 1.3 or any later version published by the Free
Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
Texts. A copy of the license is included in the section entitled 'GNU Free Documentation
License'.
Table of Contents
I. apache and squid .................................................................................................................. 1
1. apache web server ...................................................................................................... 3
1.1. introduction to apache ........................................................................................ 4
1.2. port virtual hosts on Debian ............................................................................... 11
1.3. port virtual hosts on CentOS .............................................................................. 14
1.4. named virtual hosts on Debian ............................................................................ 18
1.5. password protected website on Debian ................................................................. 20
1.6. troubleshooting apache on Debian ....................................................................... 21
1.7. virtual hosts example ........................................................................................ 22
1.8. aliases and redirects .......................................................................................... 22
1.9. more on .htaccess ............................................................................................. 22
1.10. traffic ........................................................................................................... 22
1.11. practice: apache .............................................................................................. 22
2. introduction to squid ................................................................................................. 24
2.1. about proxy servers .......................................................................................... 24
2.2. squid proxy server ............................................................................................ 24
II. mysql database .................................................................................................................. 28
3. introduction to sql using mysql ................................................................................... 30
3.1. installing mysql ............................................................................................... 31
3.2. accessing mysql ............................................................................................... 32
3.3. mysql databases ............................................................................................... 34
3.4. mysql tables .................................................................................................... 36
3.5. mysql records .................................................................................................. 38
3.6. joining two tables ............................................................................................. 41
3.7. mysql triggers .................................................................................................. 42
III. dns server ........................................................................................................................ 44
4. introduction to DNS .................................................................................................. 46
4.1. about dns ........................................................................................................ 47
4.2. dns namespace ................................................................................................. 49
4.3. caching only servers ......................................................................................... 54
4.4. authoritative dns servers .................................................................................... 56
4.5. primary and secondary ...................................................................................... 56
4.6. zone transfers .................................................................................................. 56
4.7. master and slave .............................................................................................. 57
4.8. SOA record ..................................................................................................... 57
4.9. full or incremental zone transfers ........................................................................ 58
4.10. DNS cache .................................................................................................... 59
4.11. forward lookup zone example ........................................................................... 60
4.12. Practice: caching only DNS server ..................................................................... 61
4.13. Practice: caching only with forwarder ................................................................. 64
4.14. Practice: primary authoritative server ................................................................. 66
4.15. Practice: reverse DNS ..................................................................................... 68
4.16. Practice: a DNS slave server ............................................................................ 69
5. advanced DNS .......................................................................................................... 70
5.1. DNS round robin ............................................................................................. 71
5.2. DNS delegation ............................................................................................... 72
5.3. DNS load balancing .......................................................................................... 73
5.4. DNS notify ..................................................................................................... 73
5.5. testing IXFR and AXFR .................................................................................... 73
5.6. DDNS integration with DHCP ............................................................................ 73
5.7. reverse is forward in-addr.arpa ........................................................................... 73
5.8. ipv6 ............................................................................................................... 74
5.9. split-horizon dns .............................................................................................. 74
5.10. DNS security : file corruption ........................................................................... 74
5.11. DNS security : zone transfers ............................................................................ 74
iv
Linux Servers
Linux Servers
vi
129
131
132
132
133
133
135
136
137
138
139
139
139
139
140
140
141
142
143
144
144
144
144
145
145
146
147
148
149
149
149
150
150
150
151
151
153
154
155
156
156
157
157
159
160
162
163
164
165
165
166
167
168
169
170
170
171
171
Linux Servers
vii
172
172
173
173
174
174
175
176
177
178
180
182
184
185
185
185
186
186
187
187
187
188
188
188
189
189
189
190
191
191
192
192
192
193
195
197
198
200
201
202
204
205
205
205
206
206
206
206
206
207
207
207
208
208
210
210
210
210
Linux Servers
viii
210
213
215
215
215
215
217
224
List of Tables
4.1.
4.2.
7.1.
7.2.
ix
51
51
92
94
Table of Contents
1. apache web server .............................................................................................................. 3
1.1. introduction to apache ................................................................................................ 4
1.2. port virtual hosts on Debian ....................................................................................... 11
1.3. port virtual hosts on CentOS ...................................................................................... 14
1.4. named virtual hosts on Debian ................................................................................... 18
1.5. password protected website on Debian ......................................................................... 20
1.6. troubleshooting apache on Debian ............................................................................... 21
1.7. virtual hosts example ................................................................................................ 22
1.8. aliases and redirects .................................................................................................. 22
1.9. more on .htaccess ..................................................................................................... 22
1.10. traffic ................................................................................................................... 22
1.11. practice: apache ...................................................................................................... 22
2. introduction to squid ......................................................................................................... 24
2.1. about proxy servers .................................................................................................. 24
2.2. squid proxy server .................................................................................................... 24
After installation, the same two commands as above will yield a different result:
root@debian7:~# ls -l /var/www
total 4
-rw-r--r-- 1 root root 177 Apr 29 11:55 index.html
root@debian7:~# dpkg -l | grep apache | tr -s ' '
ii apache2 2.2.22-13+deb7u1 amd64 Apache HTTP Server metapackage
ii apache2-mpm-worker 2.2.22-13+deb7u1 amd64 Apache HTTP Server - high speed th\
readed model
ii apache2-utils 2.2.22-13+deb7u1 amd64 utility programs for webservers
ii apache2.2-bin 2.2.22-13+deb7u1 amd64 Apache HTTP Server common binary files
ii apache2.2-common 2.2.22-13+deb7u1 amd64 Apache HTTP Server common files
After running the yum install httpd command, the Centos 6.5 server has apache installed
and the /var/www directory exists.
[root@centos65 ~]# rpm -q httpd
httpd-2.2.15-30.el6.centos.x86_64
[root@centos65 ~]# ls -l /var/www
total 16
drwxr-xr-x. 2 root root 4096 Apr
drwxr-xr-x. 3 root root 4096 May
drwxr-xr-x. 2 root root 4096 Apr
drwxr-xr-x. 3 root root 4096 May
[root@centos65 ~]#
3
6
3
6
23:57
13:08
23:57
13:08
cgi-bin
error
html
icons
To verify, run the service apache2 status command again or use ps.
root@debian7:~# service apache2 status
Apache2 is running (pid 3680).
root@debian7:~# ps -C apache2
PID TTY
TIME CMD
3680 ?
00:00:00 apache2
3683 ?
00:00:00 apache2
3684 ?
00:00:00 apache2
3685 ?
00:00:00 apache2
root@debian7:~#
Or use wget and file to verify that your web server serves an html document.
root@debian7:~# wget 127.0.0.1
--2014-05-06 13:27:02-- http://127.0.0.1/
Connecting to 127.0.0.1:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 177 [text/html]
Saving to: `index.html'
100%[==================================================>] 177
--.-K/s
in 0s
Or verify that apache is running by opening a web browser, and browse to the ip-address of
your server. An Apache test page should be shown.
You can do the following to quickly avoid the 'could not reliably determine the fqdn' message
when restarting apache.
root@debian7:~# echo ServerName Debian7 >> /etc/apache2/apache2.conf
root@debian7:~# service apache2 restart
Restarting web server: apache2 ... waiting .
root@debian7:~#
To verify that apache is running, use ps or issue the service httpd status command again.
[root@centos65 ~]# service httpd status
httpd (pid 2410) is running...
[root@centos65 ~]# ps -C httpd
PID TTY
TIME CMD
2410 ?
00:00:00 httpd
2412 ?
00:00:00 httpd
2413 ?
00:00:00 httpd
2414 ?
00:00:00 httpd
2415 ?
00:00:00 httpd
2416 ?
00:00:00 httpd
2417 ?
00:00:00 httpd
2418 ?
00:00:00 httpd
2419 ?
00:00:00 httpd
[root@centos65 ~]#
To prevent the 'Could not reliably determine the fqdn' message, issue the following
command.
[root@centos65 ~]# echo ServerName Centos65 >> /etc/httpd/conf/httpd.conf
[root@centos65 ~]# service httpd restart
Stopping httpd:
[ OK ]
Starting httpd:
[ OK ]
[root@centos65 ~]#
Instead when visiting the ip-address of your server in a web browser you get a noindex.html
page. You can verify this using wget.
[root@centos65 ~]# wget http://127.0.0.1/error/noindex.html
--2014-05-06 15:16:05-- http://127.0.0.1/error/noindex.html
Connecting to 127.0.0.1:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5039 (4.9K) [text/html]
Saving to: noindex.html
100%[=============================================>] 5,039
--.-K/s
in 0s
Any custom index.html file in /var/www/html will immediately serve as an index for this
web server.
[root@centos65 ~]# echo 'Welcome to my website' > /var/www/html/index.html
[root@centos65 ~]# wget http://127.0.0.1
--2014-05-06 15:19:16-- http://127.0.0.1/
Connecting to 127.0.0.1:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 22 [text/html]
Saving to: index.html
100%[=============================================>] 22
2014-05-06 15:19:16 (1.95 MB/s) - index.html saved [22/22]
[root@centos65 ~]# cat index.html
Welcome to my website
--.-K/s
in 0s
RHEL/CentOS have no default web page (only the noindex.html error page mentioned
before). But an index.html file created in /var/www/html/ will automatically be used as
default page.
[root@centos65 ~]# echo '<html><head><title>Default website</title></head><body\
><p>A new web page</p></body></html>' > /var/www/html/index.html
[root@centos65 ~]# cat /var/www/html/index.html
<html><head><title>Default website</title></head><body><p>A new web page</p></b\
ody></html>
[root@centos65 ~]#
ls -l /etc/httpd/
root 4096 May
root 4096 May
root
19 May
root
29 May
6
6
6
6
root
19 May
13:08
13:08
13:08
13:08
conf
conf.d
logs -> ../../var/log/httpd
modules -> ../../usr/lib64/httpd/modu\
14:23
13:19
18:35
2013
13:19
13:19
12:13
13:19
13:19
10
apache2.conf
conf.d
envvars
magic
mods-available
mods-enabled
ports.conf
sites-available
sites-enabled
Notice the different port numbers 7000, 8000 and 9000. Notice also that we specified a
unique DocumentRoot for each website.
11
12
--.-K/s
in 0s
--.-K/s
in 0s
--.-K/s
in 0s
Try testing from another computer using the ip-address of your server.
13
Notice the different port numbers 7000, 8000 and 9000. Notice also that we specified a
unique DocumentRoot for each website.
14
This is due to SELinux reserving ports 7000 and 8000 for other uses. We need to tell SELinux
we want to use these ports for http traffic
[root@CentOS65 ~]# semanage port -m -t http_port_t -p tcp 7000
[root@CentOS65 ~]# semanage port -m -t http_port_t -p tcp 8000
[root@CentOS65 ~]# service httpd restart
Stopping httpd:
[ OK
Starting httpd:
[ OK
]
]
15
README
welcome.conf
--.-K/s
in 0s
--.-K/s
in 0s
--.-K/s
in 0s
16
~]#
~]#
~]#
~]#
iptables
iptables
iptables
iptables
-I
-I
-I
-I
INPUT
INPUT
INPUT
INPUT
-p
-p
-p
-p
tcp
tcp
tcp
tcp
--dport
--dport
--dport
--dport
80 -j ACCEPT
7000 -j ACCEPT
8000 -j ACCEPT
9000 -j ACCEPT
And if we want these rules to remain active after a reboot, we need to save them
[root@CentOS65 ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[
17
OK
vi choochoo.local
vi chessclub42.local
vi hunter2.local
cat choochoo.local
cat chessclub42.local
cat hunter2.local
Notice that they all listen on port 80 and have an extra ServerName directive.
18
19
--.-K/s
in 0s
Hacker rob also wants access, this screenshot shows how to add a second user and password
to .htpasswd.
root@debian7:~# htpasswd /var/www/.htpasswd rob
New password:
Re-type new password:
Adding password for user rob
root@debian7:~# cat /var/www/.htpasswd
cliff:$apr1$vujll0KL$./SZ4w9q0swhX93pQ0PVp.
rob:$apr1$HNln1FFt$nRlpF0H.IW11/1DRq4lQo0
Both Cliff and Rob chose the same password (hunter2), but that is not visible in the
.htpasswd file because of the different salts.
Next we need to create a .htaccess file in the DocumentRoot of the website we want to
protect. This screenshot shows an example.
root@debian7:~# cd /var/www/hunter2/
root@debian7:/var/www/hunter2# cat .htaccess
AuthUserFile /var/www/.htpasswd
AuthName "Members only!"
AuthType Basic
require valid-user
Note that we are protecting the website on port 9000 that we created earlier.
And because we put the website for the Hackerspace named hunter2 in a subdirectory of the
default website, we will need to adjust the AllowOvveride parameter in /etc/apache2/sitesavailable/default as this screenshot shows (with line numbers on Debian7, your may vary).
9
10
11
12
13
14
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride Authconfig
Order allow,deny
allow from all
</Directory
20
Let us force another error by renaming the directory of one of our websites:
root@debian7:~# mv /var/www/choochoo/ /var/www/chooshoo
root@debian7:~# !ser
service apache2 restart
Restarting web server: apache2Warning: DocumentRoot [/var/www/choochoo] does n\
ot exist
Warning: DocumentRoot [/var/www/choochoo] does not exist
... waiting Warning: DocumentRoot [/var/www/choochoo] does not exist
Warning: DocumentRoot [/var/www/choochoo] does not exist
.
As you can see, apache will tell you exactly what is wrong.
You can also troubleshoot by connecting to the website via a browser and then checking the
apache log files in /var/log/apache.
21
1.10. traffic
Apache keeps a log of all visitors. The webalizer is often used to parse this log into nice
html statistics.
22
23
2.1.3. squid
This chapter is an introduction to the squid proxy server (http://www.squid-cache.org). The
version used is 2.5.
[root@RHEL4 ~]# rpm -qa | grep squid
squid-2.5.STABLE6-3.4E.12
[root@RHEL4 ~]#
24
introduction to squid
2.2.2. /var/spool/squid
The squid proxy server stores its cache by default in /var/spool/squid. This setting is
configurable in /etc/squid/squid.conf.
[root@RHEL4 ~]# grep "^# cache_dir" /etc/squid/squid.conf
# cache_dir ufs /var/spool/squid 100 16 256
It is possible that in a default setup where squid has never run, that the /var/spool/squid
directories do not exist.
[root@RHEL4 ~]# ls -al /var/spool/squid
ls: /var/spool/squid: No such file or directory
2.2.4. /var/log/squid
The standard log file location for squid is /var/log/squid.
[root@RHEL4 ~]# grep "/var/log" /etc/squid/squid.conf
# cache_access_log /var/log/squid/access.log
# cache_log /var/log/squid/cache.log
# cache_store_log /var/log/squid/store.log
25
introduction to squid
Restart the squid server, and now the local private network can use the proxy cache.
Then configure a browser on a client to use the proxy server. OR you could set the
HTTP_PROXY (sometimes http_proxy) variable to point command line programs to the
proxy.
[root@fedora ~]# export HTTP_PROXY=http://192.168.1.39:8080
[root@ubuntu ~]# export http_proxy=http://192.168.1.39:8080
Testing a client machine can then be done with wget (wget -q is used to simplify the
screenshot).
[root@RHEL5 ~]# > /etc/resolv.conf
[root@RHEL5 ~]# wget -q http://www.linux-training.be/index.html
[root@RHEL5 ~]# ls -l index.html
-rw-r--r-- 1 root root 2269 Sep 18 2008 index.html
[root@RHEL5 ~]#
26
introduction to squid
--.-K/s
27
in 0.1s
Table of Contents
3. introduction to sql using mysql ...........................................................................................
3.1. installing mysql .......................................................................................................
3.2. accessing mysql .......................................................................................................
3.3. mysql databases .......................................................................................................
3.4. mysql tables ............................................................................................................
3.5. mysql records ..........................................................................................................
3.6. joining two tables .....................................................................................................
3.7. mysql triggers ..........................................................................................................
29
30
31
32
34
36
38
41
42
30
During the installation you will be asked to provide a password for the root mysql user,
remember this password (or use hunter2 like i do.
To verify the installed version, use dpkg -l on Debian/Ubuntu. This screenshot shows
version 5.0 installed.
root@ubu1204~# dpkg -l mysql-server | tail -1 | tr -s ' ' | cut -c-72
ii mysql-server 5.5.24-0ubuntu0.12.04.1 MySQL database server (metapacka
31
The mysql daemon mysqld will run with the credentials of this user and group.
root@ubu1204~# ps -eo uid,user,gid,group,comm | grep mysqld
120 mysql
131 mysql
mysqld
You could also put the password in clear text on the command line, but that would not be
very secure. Anyone with access to your bash history would be able to read your mysql root
password.
root@ubu1204~# mysql -u root -phunter2
Welcome to the MySQL monitor. Commands end with ; or \g.
...
32
3.2.3. ~/.my.cnf
You can save configuration in your home directory in the hidden file .my.cnf. In the
screenshot below we put the root user and password in .my.cnf.
kevin@ubu1204:~$ pwd
/home/kevin
kevin@ubu1204:~$ cat .my.cnf
[client]
user=root
password=hunter2
kevin@ubu1204:~$
This enables us to log on as the root mysql user just by typing mysql.
kevin@ubu1204:~$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 56
Server version: 5.5.24-0ubuntu0.12.04.1 (Ubuntu)
33
34
35
You are allowed to type the create table command on one long line, but administrators often
use multiple lines to improve readability.
mysql> create table country ( countrycode char(3) NOT NULL, countryname\
varchar(70) NOT NULL, population int, countrycapital varchar(50), prim\
ary key (countrycode) );
Query OK, 0 rows affected (0.18 sec)
36
37
Some administrators prefer to use uppercase for sql keywords. The mysql client accepts
both.
mysql> INSERT INTO country VALUES ('FR','France','64000000','Paris');
Query OK, 1 row affected (0.00 sec)
Note that you get an error when using a duplicate primary key.
mysql> insert into country values ('DE','Germany','82000000','Berlin');
ERROR 1062 (23000): Duplicate entry 'DE' for key 'PRIMARY'
38
39
Using the order by clause, we can change the order in which the records are presented.
mysql> select countryname,population from country order by countryname;
+---------------+------------+
| countryname
| population |
+---------------+------------+
| Belgium
|
11000000 |
| China
| 1400000000 |
| Egypt
|
82000000 |
| France
|
64000000 |
| Germany
|
82000000 |
| India
| 1300000000 |
| Japan
| 128000000 |
| Mexico
| 113000000 |
| Spain
|
48000000 |
| United States | 313000000 |
+---------------+------------+
10 rows in set (0.00 sec)
40
41
| Liu Yang
| astronaut | China
|
| Serena Williams | tennis
| United States |
| Venus Williams | tennis
| United States |
+-----------------+-----------+---------------+
9 rows in set (0.00 sec)
This inner join will show only records with a match on countrycode in both tables.
You can see that some countries are present, even when they have no matching records in
the people table.
We can let mysql do the calculation for that by using a before trigger. The screenshot below
shows the creation of a trigger that calculates the amount by multiplying two fields that are
about to be inserted.
mysql> create trigger total_amount before INSERT on invoices
42
Here we verify that the trigger works by inserting a new record, without providing the total
amount.
mysql> insert into invoices values ('20090526','ABC','199','10','');
Query OK, 1 row affected (0.02 sec)
43
Table of Contents
4. introduction to DNS ..........................................................................................................
4.1. about dns ................................................................................................................
4.2. dns namespace .........................................................................................................
4.3. caching only servers .................................................................................................
4.4. authoritative dns servers ............................................................................................
4.5. primary and secondary ..............................................................................................
4.6. zone transfers ..........................................................................................................
4.7. master and slave ......................................................................................................
4.8. SOA record .............................................................................................................
4.9. full or incremental zone transfers ................................................................................
4.10. DNS cache ............................................................................................................
4.11. forward lookup zone example ...................................................................................
4.12. Practice: caching only DNS server .............................................................................
4.13. Practice: caching only with forwarder ........................................................................
4.14. Practice: primary authoritative server .........................................................................
4.15. Practice: reverse DNS .............................................................................................
4.16. Practice: a DNS slave server ....................................................................................
5. advanced DNS ..................................................................................................................
5.1. DNS round robin .....................................................................................................
5.2. DNS delegation .......................................................................................................
5.3. DNS load balancing .................................................................................................
5.4. DNS notify .............................................................................................................
5.5. testing IXFR and AXFR ............................................................................................
5.6. DDNS integration with DHCP ....................................................................................
5.7. reverse is forward in-addr.arpa ...................................................................................
5.8. ipv6 .......................................................................................................................
5.9. split-horizon dns ......................................................................................................
5.10. DNS security : file corruption ...................................................................................
5.11. DNS security : zone transfers ....................................................................................
5.12. DNS security : zone transfers, ip spoofing ...................................................................
5.13. DNS security : queries .............................................................................................
5.14. DNS security : chrooted bind ....................................................................................
5.15. DNS security : DNSSEC ..........................................................................................
5.16. DNS security : root .................................................................................................
45
46
47
49
54
56
56
56
57
57
58
59
60
61
64
66
68
69
70
71
72
73
73
73
73
73
74
74
74
74
74
74
75
75
75
46
introduction to DNS
In wireshark you can use the dns filter to see this traffic.
4.1.2. history
In the Seventies, only a few hundred computers were connected to the internet. To resolve
names, computers had a flat file that contained a table to resolve hostnames to ip-addresses.
This local file was downloaded from hosts.txt on an ftp server in Stanford.
In 1984 Paul Mockapetris created dns, a distributed treelike hierarchical database that will
be explained in detail in these chapters.
Today, dns or domain name system is a worldwide distributed hierarchical database
controlled by ICANN. Its primary function is to resolve names to ip addresses, and to point
to internet servers providing smtp or ldap services.
The old hosts.txt file is still active today on most computer systems under the name /etc/
hosts. We will discuss this file later, as it can influence name resolution.
47
introduction to DNS
This is what a reverse lookup looks like when sniffing with wireshark.
4.1.4. /etc/resolv.conf
A client computer needs to know the ip-address of the dns server to be able to send queries
to it. This is either provided by a dhcp server or manually entered.
Linux clients keep this information in the /etc/resolv.conf file.
paul@ubu1010:~$ cat /etc/resolv.conf
nameserver 212.71.8.10
48
introduction to DNS
49
introduction to DNS
198.41.0.4
192.228.79.201
192.33.4.12
128.8.10.90
192.203.230.10
192.5.5.241
192.112.36.4
128.63.2.53
192.36.148.17
192.58.128.30
193.0.14.129
199.7.83.42
202.12.27.33
4.2.4. domains
One level below the top level domains are the domains. Domains can have subdomains
(also called child domains).
This picture shows dns domains like google.com, chess.com, linux-training.be (there are
millions more).
DNS domains are registered at the tld servers, the tld servers are registered at the dot
servers.
50
introduction to DNS
TLD
purpose
1985
.arpa
1985
.com
Commercial Organizations
1985
.edu
US Educational Institutions
1985
.gov
US Government Institutions
1985
.mil
US Military
1985
.net
1985
.org
1988
.int
Country tld's were defined for individual countries, like .uk in 1985 for Great Britain (yes
really), .be for Belgium in 1988 and .fr for France in 1986. See RFC 1591 for more info.
In 1998 seven new general purpose tld's where chosen, they became active in the 21st
century.
Table 4.2. new general purpose tld's
year
TLD
purpose
2002
.aero
aviation related
2001
.biz
businesses
2001
.coop
for co-operatives
2001
.info
2001
.museum
2001
.name
2004
.pro
for museums
for all kinds of names, pseudonyms and labels...
for professionals
Many people were surprised by the choices, claiming not much use for them and wanting
a separate .xxx domain (introduced in 2011) for adult content, and .kidz a save haven for
children. In the meantime more useless tld's were create like .travel (for travel agents) and
.tel (for internet communications) and .jobs (for jobs sites).
51
introduction to DNS
A dns server can be authoritative over 0, 1 or more dns zones. We will see more details
later on the relation between a dns server and a dns zone.
A dns zone consists of records, also called resource records. We will list some of those
resource records on the next page.
52
introduction to DNS
PTR record
A PTR record is the reverse of an A record. It contains the name of a computer and can be
used to resolve an ip-address to a hostname.
NS record
A NS record or nameserver record is a record that points to a DNS name server (in this
zone). You can list all your name servers for your DNS zone in distinct NS records.
glue A record
An A record that maps the name of an NS record to an ip address is said to be a glue record.
SOA record
The SOA record of a zone contains meta information about the zone itself. The contents of
the SOA record is explained in detail in the section about zone transfers. There is exactly
one SOA record for each zone.
CNAME record
A CNAME record maps a hostname to a hostname, creating effectively an alias for an
existing hostname. The name of the mail server is often aliased to mail or smtp, and the
name of a web server to www.
MX record
The MX record points to an smtp server. When you send an email to another domain, then
your mail server will need the MX record of the target domain's mail server.
53
introduction to DNS
This picture shows a dns server on the company LAN that has set the dns server from their
isp as a forwarder. If the ip address of the isp dns server is 212.71.8.10, then the following
lines would occur in the named.conf file of the company dns server:
forwarders {
212.71.8.10;
};
54
introduction to DNS
55
introduction to DNS
56
introduction to DNS
Zone transfers only occur when the zone database was updated (meaning when one or more
resource records were added, removed or changed on the master server). The slave server
57
introduction to DNS
will compare the serial number of its own copy of the SOA record with the serial number
of its master's SOA record. When both serial numbers are the same, then no update is needed
(because no records were added, removed or deleted). When the slave has a lower serial
number than its master, then a zone transfer is requested.
Below a zone transfer captured in wireshark.
58
introduction to DNS
59
introduction to DNS
To create the zone file, the easy method is to copy an existing zone file (this is easier than
writing from scratch).
[root@RHEL4b
[root@RHEL4b
/var/named
[root@RHEL4b
[root@RHEL4b
named]# cd /var/named/
named]# pwd
named]# cp localhost.zone classdemo.local.zone
named]#
IN
IN
IN
IN
IN
10
A
A
A
A
A
rhel4b.classdemo.local.
mail.classdemo.local.
192.168.1.191
192.168.1.191
192.168.1.191
192.168.1.191
192.168.1.191
192.168.1.1
60
introduction to DNS
[ OK ]
1/1
Installed:
bind.i686 32:9.7.3-1.fc14
Complete!
[root@fedora14 ~]# rpm -qa | grep bind
samba-winbind-clients-3.5.8-74.fc14.i686
bind-utils-9.7.3-1.fc14.i686
PackageKit-device-rebind-0.6.12-2.fc14.i686
bind-libs-9.7.3-1.fc14.i686
bind-9.7.3-1.fc14.i686
[root@fedora14 ~]#
2. Discover the default configuration files. Can you define the purpose of each file ?
61
introduction to DNS
2a. On Fedora:
[root@fedora14 ~]# ls -ld /etc/named*
drwxr-x---. 2 root named 4096 Feb 18 16:07 /etc/named
-rw-r-----. 1 root named 1008 Jul 19 2010 /etc/named.conf
-rw-r--r--. 1 root named 2544 Feb 18 16:07 /etc/named.iscdlv.key
-rw-r-----. 1 root named 931 Jun 21 2007 /etc/named.rfc1912.zones
-rw-r--r--. 1 root named 487 Jul 19 2010 /etc/named.root.key
[root@fedora14 ~]# ls -l /var/named/
total 28
drwxrwx---. 2 named named 4096 Feb 18 16:07 data
drwxrwx---. 2 named named 4096 Feb 18 16:07 dynamic
-rw-r-----. 1 root named 1892 Feb 18 2008 named.ca
-rw-r-----. 1 root named 152 Dec 15 2009 named.empty
-rw-r-----. 1 root named 152 Jun 21 2007 named.localhost
-rw-r-----. 1 root named 168 Dec 15 2009 named.loopback
drwxrwx---. 2 named named 4096 Feb 18 16:07 slaves
2. On Ubuntu:
root@ubu1010srv:~# ls -l /etc/bind
total 52
-rw-r--r-- 1 root root 601 2011-02-23
-rw-r--r-- 1 root root 237 2011-02-23
-rw-r--r-- 1 root root 271 2011-02-23
-rw-r--r-- 1 root root 237 2011-02-23
-rw-r--r-- 1 root root 353 2011-02-23
-rw-r--r-- 1 root root 270 2011-02-23
-rw-r--r-- 1 root root 2994 2011-02-23
-rw-r--r-- 1 root bind 463 2011-02-23
-rw-r--r-- 1 root bind 490 2011-02-23
-rw-r--r-- 1 root bind 165 2011-02-23
-rw-r--r-- 1 root bind 572 2011-02-23
-rw-r----- 1 bind bind
77 2011-05-15
-rw-r--r-- 1 root root 1317 2011-02-23
16:22
16:22
16:22
16:22
16:22
16:22
16:22
16:22
16:22
16:22
16:22
17:52
16:22
bind.keys
db.0
db.127
db.255
db.empty
db.local
db.root
named.conf
named.conf.default-zones
named.conf.local
named.conf.options
rndc.key
zones.rfc1918
3. Setup caching only dns server. This is normally the default setup. A caching-only name
server will look up names for you and cache them. Most tutorials will tell you to add a
forwarder, so we first try without this!
root@ubu1010srv:/var/log# nslookup
> server 192.168.1.37
Default server: 192.168.1.37
Address: 192.168.1.37#53
>
> slashdot.org
Server: 192.168.1.37
Address: 192.168.1.37#53
Non-authoritative answer:
Name: slashdot.org
Address: 216.34.181.45
Hey this seems to work without a forwarder. Using a sniffer you can find out what really
happens (since the server is not using a cache, not using your dns-server (from /etc/
resolv.conf). So where is this information coming from, and what can you learn from sniffing
this dns traffic ?
4. Explain in detail what happens when you enable a caching only dns server without
forwarder. This wireshark screenshot can help, but you learn more by sniffing the traffic
yourself! I will choose two volunteers to explain this in front of the class.
62
introduction to DNS
63
introduction to DNS
/etc/init.d/bind9 restart
name service... bind9
name service... bind9
[ OK ]
[ OK ]
6. Explain the purpose of adding the forwarder. What is our DNS server doing when it
receives a query ? Again the wireshark screenshot can help, you should see something
similar.
root@ubu1010srv:~# nslookup
> server
Default server: 192.168.1.4
Address: 192.168.1.4#53
> server 192.168.1.37
Default server: 192.168.1.37
Address: 192.168.1.37#53
>
> cobbaut.be
Server: 192.168.1.37
Address: 192.168.1.37#53
Non-authoritative answer:
Name: cobbaut.be
Address: 88.151.243.8
7. What happens when you query for the same domain name more than once ?
64
introduction to DNS
10. How can we avoid having to set the server in dig or nslookup ?
root@ubu1010srv:~# cat /etc/resolv.conf
nameserver 127.0.0.1
11. When you use dig for the first time for a domain, where is the answer coming from ?
And the second time ? How can you tell ?
65
introduction to DNS
3. Also add a zone database file, similar to this one (add some A records for testing). Set the
Refresh and Retry values not too high so you can sniff this traffic (this example makes the
slave server contact the master every 300 seconds).
root@ubu1010srv:/etc/bind# cat db.cobbaut.paul
;
; BIND data file for domain cobbaut.paul
;
$TTL 604800
@ IN SOA ns.cobbaut.paul. root.cobbaut.paul. (
20110516
; Serial
300
; Refresh
200
; Retry
2419200
; Expire
604800 )
; Negative Cache TTL
;
@
IN
NS
ns.cobbaut.paul.
ns
IN
A
192.168.1.37
ubu1010srv
IN
A
192.168.1.37
anya
IN
A
192.168.1.1
mac
IN
A
192.168.1.30
root@ubu1010srv:/etc/bind#
4. Restart the DNS server and check your zone in the error log.
root@ubu1010srv:/etc/bind# grep cobbaut /var/log/daemon.log
May 16 00:33:49 ubu1010srv named[25449]: zone cobbaut.paul/IN: loaded\
serial 20110516
66
introduction to DNS
root@ubu1010srv:/etc/bind#
6. Our primary server appears to be up and running. Note the information here:
server os : Ubuntu 10.10
ip : 192.168.1.37
domain name: cobbaut.paul
server name: ns.cobbaut.paul
67
introduction to DNS
3. Also create a zone database file for this reverse lookup zone.
root@ubu1010srv:/etc/bind# cat db.192
;
; BIND reverse data file for 192.168.1.0/24 network
;
$TTL 604800
@ IN SOA ns.cobbaut.paul root.cobbaut.paul. (
20110516 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.
37 IN PTR ns.cobbaut.paul.
1 IN PTR anya.cobbaut.paul.
30 IN PTR mac.cobbaut.paul.
root@ubu1010srv:/etc/bind#
68
introduction to DNS
3. My slave server is running Fedora 14. Bind configuration files are only a little different.
Below the addition of a slave zone to this server, note the ip address (192.168.1.37) of my
master dns server for the cobbaut.paul zone.
[root@fedora14 etc]# grep cobbaut -A2 named.conf
zone "cobbaut.paul" {
type slave;
file "/var/named/slaves/db.cobbaut.paul";
masters { 192.168.1.37; };
};
[root@fedora14 etc]#
4. You might need to add the ip-address of the server on Fedora to allow queries other than
from localhost.
[root@fedora14 etc]# grep 127 named.conf
listen-on port 53 { 127.0.0.1; 192.168.1.31; };
5. Restarting bind on the slave server should transfer the zone database file:
[root@fedora14 etc]# ls -l /var/named/slaves/
total 4
-rw-r--r--. 1 named named 387 May 16 03:23 db.cobbaut.paul
[root@fedora14 etc]#
69
70
advanced DNS
IN A 192.168.1.20
IN A 192.168.1.22
Below a screenshot of nslookup querying a load balanced A record. Notice the order of ipaddresses returned.
> server 192.168.1.35
Default server: 192.168.1.35
Address: 192.168.1.35#53
> faith.cobbaut.paul
Server: 192.168.1.35
Address: 192.168.1.35#53
Name: faith.cobbaut.paul
Address: 192.168.1.20
Name: faith.cobbaut.paul
Address: 192.168.1.22
> faith.cobbaut.paul
Server: 192.168.1.35
Address: 192.168.1.35#53
Name: faith.cobbaut.paul
Address: 192.168.1.22
Name: faith.cobbaut.paul
Address: 192.168.1.20
> faith.cobbaut.paul
Server: 192.168.1.35
Address: 192.168.1.35#53
Name: faith.cobbaut.paul
Address: 192.168.1.20
Name: faith.cobbaut.paul
Address: 192.168.1.22
71
advanced DNS
72
advanced DNS
73
advanced DNS
child domain having again 256 child domains. And this twice more to a structure of over
four billion (2 to the power 32) domains.
5.8. ipv6
With rfc 3596 came ipv6 extensions for DNS. There is the AAAA record for ipv6 hosts on
the network, and there is the ip6.int domain for reverse lookup (having 16 child domains
from 0.ip6.int to f.ip6.int, each of those having again 16 child domains...and this 16 times.
74
advanced DNS
view "internal" {
match-clients { 192.168.42/24; };
recursion yes;
...
};
view "external" {
match-clients { any; };
recursion no;
...
};
75
Table of Contents
6. introduction to dhcp ..........................................................................................................
6.1. four broadcasts ........................................................................................................
6.2. picturing dhcp .........................................................................................................
6.3. installing a dhcp server .............................................................................................
6.4. dhcp server on Red Hat .............................................................................................
6.5. dhcp options ............................................................................................................
6.6. client reservations ....................................................................................................
6.7. example config files .................................................................................................
6.8. older example config files .........................................................................................
6.9. advanced dhcp .........................................................................................................
6.10. Practice: dhcp ........................................................................................................
77
78
79
80
81
81
81
81
82
82
84
85
78
introduction to dhcp
When this procedure is finished, then the client is allowed to use that ip-configuration until
the end of its lease time.
79
introduction to dhcp
1. The client SunWS1 sends a dhcp discover on the network. All computers receive this
broadcast.
2. Both dhcp servers answer with a dhcp offer. DHCP-SRV1 is a dedicated dhcp server
and is faster in sending a dhcp offer than DHCP-SRV2 (who happens to also be a file server).
3. The client chooses the offer from DHCP-SRV1 and sends a dhcp request on the network.
4. DHCP-SRV1 answers with a dhcp ack (short for acknowledge).
All four broadcasts (or five when you count both offers) can be layer 2 ethernet broadcast
to mac address ff:ff:ff:ff:ff:ff and a layer 3 ip broadcast to 255.255.255.255.
The same story can be read in rfc 2131.
80
introduction to dhcp
So we copy the sample and adjust it for our real situation. We name the copy /etc/
dhcpd.conf.
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.140 192.168.1.159
option routers
192.168.1.1;
option subnet-mask
255.255.255.0;
option domain-name
"classdemo.local";
option domain-name-servers
192.168.1.1;
default-lease-time
21600;
}
subnet-mask 255.255.255.0;
domain-name "linux-training.be";
domain-name-servers "ns1.openminds.be";
routers 192.168.42.1;
81
introduction to dhcp
Above the general configuration for the network, with a pool of 180 addresses.
Below two client reservations:
#
# laptops
#
host mac {
hardware ethernet 00:26:bb:xx:xx:xx;
fixed-address mac.netsec.local;
}
host vmac {
hardware ethernet 8c:7b:9d:xx:xx:xx;
fixed-address vmac.netsec.local;
}
82
introduction to dhcp
Allowing any updates in the zone database (part of the named.conf configuration)
zone "office.linux-training.be" {
type master;
file "/var/named/db.office.linux-training.be";
allow-transfer { any; };
allow-update { any; };
};
Allowing secure key updates in the zone database (part of the named.conf configuration)
zone "office.linux-training.be" {
type master;
file "/var/named/db.office.linux-training.be";
allow-transfer { any; };
allow-update { key mykey; };
};
Also make sure that bind can write to your db.zone file (using chmod/chown). For Ubuntu
this can be in /etc/bind, for Fedora in /var/named.
83
introduction to dhcp
84
introduction to dhcp
85
Table of Contents
7. introduction to routers ...................................................................................................... 88
7.1. router or firewall ...................................................................................................... 89
7.2. packet forwarding .................................................................................................... 89
7.3. packet filtering ........................................................................................................ 89
7.4. stateful ................................................................................................................... 89
7.5. nat (network address translation) ................................................................................. 90
7.6. pat (port address translation) ...................................................................................... 90
7.7. snat (source nat) ...................................................................................................... 90
7.8. masquerading .......................................................................................................... 90
7.9. dnat (destination nat) ................................................................................................ 90
7.10. port forwarding ...................................................................................................... 90
7.11. /proc/sys/net/ipv4/ip_forward .................................................................................... 91
7.12. /etc/sysctl.conf ........................................................................................................ 91
7.13. sysctl .................................................................................................................... 91
7.14. practice: packet forwarding ...................................................................................... 92
7.15. solution: packet forwarding ...................................................................................... 94
8. iptables firewall ................................................................................................................ 97
8.1. iptables tables .......................................................................................................... 98
8.2. starting and stopping iptables ..................................................................................... 98
8.3. the filter table .......................................................................................................... 99
8.4. practice: packet filtering .......................................................................................... 104
8.5. solution: packet filtering .......................................................................................... 105
8.6. network address translation ...................................................................................... 106
87
88
introduction to routers
7.4. stateful
A stateful firewall is an advancement over stateless firewalls that inspect every individual
packet. A stateful firewall will keep a table of active connections, and is knowledgeable
enough to recognise when new connections are part of an active session. Linux iptables is
a stateful firewall.
89
introduction to routers
7.8. masquerading
Masquerading is a form of snat that will hide the (private) source ip-addresses of your
private network using a public ip-address. Masquerading is common on dynamic internet
interfaces (broadband modem/routers). Masquerade configuration with iptables uses a
dynamic target source address.
90
introduction to routers
7.11. /proc/sys/net/ipv4/ip_forward
Whether a host is forwarding packets is defined in /proc/sys/net/ipv4/ip_forward. The
following screenshot shows how to enable packet forwarding on Linux.
root@router~# echo 1 > /proc/sys/net/ipv4/ip_forward
7.12. /etc/sysctl.conf
By default, most Linux computers are not configured for automatic packet forwarding.
To enable packet forwarding whenever the system starts, change the net.ipv4.ip_forward
variable in /etc/sysctl.conf to the value 1.
root@router~# grep ip_forward /etc/sysctl.conf
net.ipv4.ip_forward = 0
7.13. sysctl
For more information, take a look at the man page of sysctl.
root@debian6~# man sysctl
root@debian6~# sysctl -a 2>/dev/null | grep ip_forward
net.ipv4.ip_forward = 0
91
introduction to routers
1. Set up two Linux machines, one on leftnet, the other on rightnet. Make sure they both
get an ip-address in the correct subnet. These two machines will be 'left' and 'right' from
the 'router'.
2. Set up a third Linux computer with three network cards, one on leftnet, the other on
rightnet. This computer will be the 'router'. Complete the table below with the relevant
names, ip-addresses and mac-addresses.
Table 7.1. Packet Forwarding Exercise
leftnet computer
the router
rightnet computer
MAC
IP
3. How can you verify whether the router will allow packet forwarding by default or not ?
Test that you can ping from the router to the two other machines, and from those two
machines to the router. Use arp -a to make sure you are connected with the correct mac
addresses.
92
introduction to routers
4. Ping from the leftnet computer to the rightnet computer. Enable and/or disable packet
forwarding on the router and verify what happens to the ping between the two networks. If
you do not succeed in pinging between the two networks (on different subnets), then use a
sniffer like wireshark or tcpdump to discover the problem.
5. Use wireshark or tcpdump -xx to answer the following questions. Does the source MAC
change when a packet passes through the filter ? And the destination MAC ? What about
source and destination IP-addresses ?
6. Remember the third network card on the router ? Connect this card to a LAN with internet
connection. On many LAN's the command dhclient eth0 just works (replace eth0 with the
correct interface).
root@router~# dhclient eth0
You now have a setup similar to this picture. What needs to be done to give internet access
to leftnet and rightnet.
93
introduction to routers
1. Set up two Linux machines, one on leftnet, the other on rightnet. Make sure they both
get an ip-address in the correct subnet. These two machines will be 'left' and 'right' from
the 'router'.
The ip configuration on your computers should be similar to the following two screenshots.
Both machines must be in a different subnet (here 192.168.60.0/24 and 192.168.70.0/24). I
created a little script on both machines to configure the interfaces.
root@left~# cat leftnet.sh
pkill dhclient
ifconfig eth0 192.168.60.8 netmask 255.255.255.0
root@right~# cat rightnet.sh
pkill dhclient
ifconfig eth0 192.168.70.9 netmask 255.255.255.0
2. Set up a third Linux computer with three network cards, one on leftnet, the other on
rightnet. This computer will be the 'router'. Complete the table below with the relevant
names, ip-addresses and mac-addresses.
root@router~# cat router.sh
ifconfig eth1 192.168.60.1 netmask 255.255.255.0
ifconfig eth2 192.168.70.1 netmask 255.255.255.0
#echo 1 > /proc/sys/net/ipv4/ip_forward
Your setup may use different ip and mac addresses than the ones in the table below.
Table 7.2. Packet Forwarding Solution
leftnet computer
the router
rightnet computer
08:00:27:f6:ab:b9
08:00:27:43:1f:5a
08:00:27:be:4a:6b
08:00:27:14:8b:17
192.168.60.8
192.168.60.1
192.168.70.1
192.168.70.9
94
introduction to routers
3. How can you verify whether the router will allow packet forwarding by default or not ?
Test that you can ping from the router to the two other machines, and from those two
machines to the router. Use arp -a to make sure you are connected with the correct mac
addresses.
This can be done with "grep ip_forward /etc/sysctl.conf" (1 is enabled, 0 is disabled) or
with sysctl -a | grep ip_for.
root@router~# grep ip_for /etc/sysctl.conf
net.ipv4.ip_forward = 0
4. Ping from the leftnet computer to the rightnet computer. Enable and/or disable packet
forwarding on the router and verify what happens to the ping between the two networks. If
you do not succeed in pinging between the two networks (on different subnets), then use a
sniffer like wireshark or tcpdump to discover the problem.
Did you forget to add a default gateway to the LAN machines ? Use route add default
gw 'ip-address'.
root@left~# route add default gw 192.168.60.1
root@right~# route add default gw 192.168.70.1
You should be able to ping when packet forwarding is enabled (and both default gateways
are properly configured). The ping will not work when packet forwarding is disabled or
when gateways are not configured correctly.
5. Use wireshark or tcpdump -xx to answer the following questions. Does the source MAC
change when a packet passes through the filter ? And the destination MAC ? What about
source and destination IP-addresses ?
Both MAC addresses are changed when passing the router. Use tcpdump -xx like this:
root@router~# tcpdump -xx -i eth1
root@router~# tcpdump -xx -i eth2
95
introduction to routers
6. Remember the third network card on the router ? Connect this card to a LAN with internet
connection. On many LAN's the command dhclient eth0 just works (replace eth0 with the
correct interface.
root@router~# dhclient eth0
You now have a setup similar to this picture. What needs to be done to give internet access
to leftnet and rightnet.
The clients on leftnet and rightnet need a working dns server. We use one of Google's
dns servers here.
echo nameserver 8.8.8.8 > /etc/resolv.conf
96
97
iptables firewall
destination
destination
destination
destination
destination
destination
[ ok ]
Debian and *buntu distributions do not have this script, but allow for an uninstall.
root@debian6~# aptitude purge iptables
98
iptables firewall
The screenshot below shows how to list the filter table and all its rules.
[root@RHEL5 ~]# iptables -t filter -nL
Chain INPUT (policy ACCEPT)
target
prot opt source
destination
destination
destination
As you can see, all three chains in the filter table are set to ACCEPT everything. ACCEPT
is the default behaviour.
99
iptables firewall
-P INPUT DROP
-P OUTPUT DROP
-P FORWARD DROP
-L
destination
destination
destination
Next, we allow the server to use its own loopback device (this allows the server to access
its services running on localhost). We first append a rule to the INPUT chain to allow
(ACCEPT) traffic from the lo (loopback) interface, then we do the same to allow packets to
leave the system through the loopback interface.
[root@RHEL5 ~]# iptables -A INPUT -i lo -j ACCEPT
[root@RHEL5 ~]# iptables -A OUTPUT -o lo -j ACCEPT
Looking at the filter table again (omitting -t filter because it is the default table).
[root@RHEL5 ~]# iptables -nL
Chain INPUT (policy DROP)
target
prot opt source
ACCEPT
all -- 0.0.0.0/0
destination
0.0.0.0/0
destination
destination
0.0.0.0/0
100
iptables firewall
The filter table will look something like this screenshot (note that -v is added for more
verbose output).
[root@RHEL5
Chain INPUT
pkts bytes
0
0
0
0
bytes)
source
0.0.0.0/0
0.0.0.0/0
destination
0.0.0.0/0
0.0.0.0/0 tcp dpt:22
destination
destination
0.0.0.0/0
0.0.0.0/0 tcp spt:22
bytes)
source
0.0.0.0/0
0.0.0.0/0
10.1.1.0/24
destination
0.0.0.0/0
0.0.0.0/0 tcp dpt:22
0.0.0.0/0
destination
destination
0.0.0.0/0
0.0.0.0/0 tcp spt:22
10.1.1.0/24
101
iptables firewall
OK
102
iptables firewall
The screenshot below shows you how to setup iptables to allow a ping from or to your
machine.
[root@RHEL5 ~]# iptables -A INPUT -p icmp --icmp-type any -j ACCEPT
[root@RHEL5 ~]# iptables -A OUTPUT -p icmp --icmp-type any -j ACCEPT
The previous two lines do not allow other computers to route ping messages through your
router, because it only handles INPUT and OUTPUT. For routing of ping, you will need
to enable it on the FORWARD chain. The following command enables routing of icmp
messages between networks.
[root@RHEL5 ~]# iptables -A FORWARD -p icmp --icmp-type any -j ACCEPT
103
iptables firewall
104
iptables firewall
105
iptables firewall
Use iptables -t nat -nvL to look at the NAT table. The screenshot below shows an empty
NAT table.
[root@RHEL5 ~]# iptables -t nat -nL
Chain PREROUTING (policy ACCEPT)
target
prot opt source
destination
destination
destination
106
iptables firewall
Of course there must exist a proper iptables filter setup to allow the packet to traverse from
one network to the other.
107
iptables firewall
8.6.4. IP masquerading
IP masquerading is very similar to SNAT, but is meant for dynamic interfaces. Typical
example are broadband 'router/modems' connected to the internet and receiving a different
ip-address from the isp, each time they are cold-booted.
The only change needed to convert the SNAT script to a masquerading is one line.
iptables -t nat -A POSTROUTING -o eth1 -s 10.1.1.0/24 -j MASQUERADE
108
Table of Contents
9. introduction to samba ...................................................................................................... 112
9.1. verify installed version ............................................................................................ 113
9.2. installing samba ..................................................................................................... 114
9.3. documentation ........................................................................................................ 115
9.4. starting and stopping samba ..................................................................................... 116
9.5. samba daemons ...................................................................................................... 117
9.6. the SMB protocol ................................................................................................... 118
9.7. practice: introduction to samba ................................................................................. 119
10. getting started with samba .............................................................................................. 120
10.1. /etc/samba/smb.conf ............................................................................................... 121
10.2. /usr/bin/testparm .................................................................................................... 122
10.3. /usr/bin/smbclient .................................................................................................. 123
10.4. /usr/bin/smbtree .................................................................................................... 125
10.5. server string ......................................................................................................... 126
10.6. Samba Web Administration Tool (SWAT) ................................................................ 127
10.7. practice: getting started with samba .......................................................................... 128
10.8. solution: getting started with samba .......................................................................... 129
11. a read only file server .................................................................................................... 131
11.1. Setting up a directory to share ................................................................................. 132
11.2. configure the share ................................................................................................ 132
11.3. restart the server ................................................................................................... 133
11.4. verify the share .................................................................................................... 133
11.5. a note on netcat .................................................................................................... 135
11.6. practice: read only file server .................................................................................. 136
11.7. solution: read only file server .................................................................................. 137
12. a writable file server ...................................................................................................... 138
12.1. set up a directory to share ...................................................................................... 139
12.2. share section in smb.conf ....................................................................................... 139
12.3. configure the share ................................................................................................ 139
12.4. test connection with windows ................................................................................. 139
12.5. test writing with windows ...................................................................................... 140
12.6. How is this possible ? ............................................................................................ 140
12.7. practice: writable file server .................................................................................... 141
12.8. solution: writable file server ................................................................................... 142
13. samba first user account ................................................................................................. 143
13.1. creating a samba user ............................................................................................ 144
13.2. ownership of files ................................................................................................. 144
13.3. /usr/bin/smbpasswd ................................................................................................ 144
13.4. /etc/samba/smbpasswd ............................................................................................ 144
13.5. passdb backend .................................................................................................... 145
13.6. forcing this user .................................................................................................... 145
13.7. practice: first samba user account ............................................................................ 146
13.8. solution: first samba user account ............................................................................ 147
14. samba authentication ..................................................................................................... 148
14.1. creating the users on Linux ..................................................................................... 149
14.2. creating the users on samba .................................................................................... 149
14.3. security = user ..................................................................................................... 149
14.4. configuring the share ............................................................................................. 150
14.5. testing access with net use ...................................................................................... 150
14.6. testing access with smbclient .................................................................................. 150
14.7. verify ownership ................................................................................................... 151
14.8. common problems ................................................................................................. 151
14.9. practice : samba authentication ................................................................................ 153
14.10. solution: samba authentication ............................................................................... 154
15. samba securing shares .................................................................................................... 155
110
Introduction to Samba
111
156
156
157
157
159
160
162
163
164
165
165
166
167
168
169
170
170
171
171
172
172
173
173
174
174
175
176
177
178
180
112
introduction to samba
The screenshot above shows that RHEL5 has Samba version 3.0 installed. The last number
in the Samba version counts the number of updates or patches.
Below the same command on a more recent version of CentOS with Samba version 3.5
installed.
[root@centos6 ~]# rpm -q samba
samba-3.5.10-116.el6_2.i686
113
introduction to samba
When you have a subscription to RHN (Red Hat Network), then yum is an easy tool to use.
This yum command works by default on Fedora and CentOS.
[root@centos6 ~]# yum install samba
114
introduction to samba
9.3. documentation
9.3.1. samba howto
Samba comes with excellent documentation in html and pdf format (and also as a free
download from samba.org and it is for sale as a printed book).
The documentation is a separate package, so install it if you want it on the server itself.
[root@centos6
...
[root@centos6
total 10916
drwxr-xr-x. 6
-rw-r--r--. 1
-rw-r--r--. 1
-rw-r--r--. 1
root
4096 May 6 15:50 htmldocs
root 4605496 Jun 14 2011 Samba3-ByExample.pdf
root 608260 Jun 14 2011 Samba3-Developers-Guide.pdf
root 5954602 Jun 14 2011 Samba3-HOWTO.pdf
This action is very similar on Ubuntu and Debian except that the pdf files are in a separate
package named samba-doc-pdf.
root@ubu1204:~# aptitude install samba-doc-pdf
The following NEW packages will be installed:
samba-doc-pdf
...
115
introduction to samba
stop
[ OK ]
start
[ OK ]
restart
[ OK ]
[ OK ]
status
[ OK ]
Red Hat derived systems are happy with service smb start.
[root@RHEL4b ~]# /etc/init.d/smb start
Starting SMB services:
Starting NMB services:
[root@RHEL4b ~]# service smb restart
Shutting down SMB services:
Shutting down NMB services:
Starting SMB services:
Starting NMB services:
[root@RHEL4b ~]#
116
[
[
OK
OK
]
]
[
[
[
[
OK
OK
OK
OK
]
]
]
]
introduction to samba
9.5.1. nmbd
The nmbd daemon takes care of all the names and naming. It registers and resolves names,
and handles browsing. According to the Samba documentation, it should be the first daemon
to start.
[root@RHEL52 ~]# ps -C nmbd
PID TTY
TIME CMD
5681 ?
00:00:00 nmbd
9.5.2. smbd
The smbd daemon manages file transfers and authentication.
[root@RHEL52 ~]# ps -C smbd
PID TTY
TIME CMD
5678 ?
00:00:00 smbd
5683 ?
00:00:00 smbd
9.5.3. winbindd
The winbind daemon (winbindd) is only started to handle Microsoft Windows domain
membership.
Note that winbindd is started by the /etc/init.d/winbind script (two dd's for the daemon and
only one d for the script).
[root@RHEL52 ~]# /etc/init.d/winbind start
Starting Winbind services:
[root@RHEL52 ~]# ps -C winbindd
PID TTY
TIME CMD
5752 ?
00:00:00 winbindd
5754 ?
00:00:00 winbindd
OK
On Debian and Ubuntu, the winbindd daemon is installed via a separate package called
winbind.
117
introduction to samba
118
introduction to samba
119
120
10.1. /etc/samba/smb.conf
10.1.1. smbd -b
Samba configuration is done in the smb.conf file. The file can be edited manually, or you
can use a web based interface like webmin or swat to manage it. The file is usually located
in /etc/samba. You can find the exact location with smbd -b.
[root@RHEL4b ~]# smbd -b | grep CONFIGFILE
CONFIGFILE: /etc/samba/smb.conf
Also on Ubuntu and Debian, smb.conf is packed with samples and explanations.
paul@laika:~$ ls -l /etc/samba/smb.conf
-rw-r--r-- 1 root root 10515 2007-05-24 00:21 /etc/samba/smb.conf
121
10.2. /usr/bin/testparm
10.2.1. syntax check smb.conf
To verify the syntax of the smb.conf file, you can use testparm.
[paul@RHEL4b ~]$ testparm
Load smb config files from /etc/samba/smb.conf
Processing section "[firstshare]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
10.2.2. testparm -v
An interesting option is testparm -v, which will output all the global options with their
default value.
[root@RHEL52 ~]# testparm -v | head
Load smb config files from /etc/samba/smb.conf
Processing section "[pub0]"
Processing section "[global$]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
[global]
dos charset = CP850
unix charset = UTF-8
display charset = LOCALE
workgroup = WORKGROUP
122
realm =
netbios name = TEACHER0
netbios aliases =
netbios scope =
server string = Samba 3.0.28-1.el5_2.1
...
There were about 350 default values for smb.conf parameters in Samba 3.0.x. This number
grew to almost 400 in Samba 3.5.x.
10.2.3. testparm -s
The samba daemons are constantly (once every 60 seconds) checking the smb.conf file, so it
is good practice to keep this file small. But it is also good practice to document your samba
configuration, and to explicitly set options that have the same default values. The testparm
-s option allows you to do both. It will output the smallest possible samba configuration file,
while retaining all your settings. The idea is to have your samba configuration in another
file (like smb.conf.full) and let testparm parse this for you. The screenshot below shows you
how. First the smb.conf.full file with the explicitly set option workgroup to WORKGROUP.
[root@RHEL4b samba]# cat smb.conf.full
[global]
workgroup = WORKGROUP
# This is a demo of a documented smb.conf
# These two lines are removed by testparm -s
server string = Public Test Server
[firstshare]
path = /srv/samba/public
Next, we execute testparm with the -s option, and redirect stdout to the real smb.conf file.
[root@RHEL4b samba]# testparm -s smb.conf.full > smb.conf
Load smb config files from smb.conf.full
Processing section "[firstshare]"
Loaded services file OK.
And below is the end result. The two comment lines and the default option are no longer
there.
[root@RHEL4b samba]# cat smb.conf
# Global parameters
[global]
server string = Public Test Server
[firstshare]
path = /srv/samba/public
[root@RHEL4b samba]#
10.3. /usr/bin/smbclient
10.3.1. smbclient looking at Samba
With smbclient you can see browsing and share information from your smb server. It will
display all your shares, your workgroup, and the name of the Master Browser. The -N switch
123
is added to avoid having to enter an empty password. The -L switch is followed by the name
of the host to check.
[root@RHEL4b init.d]# smbclient -NL rhel4b
Anonymous login successful
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.0.10-1.4E.9]
Sharename
Type
Comment
-----------------firstshare
Disk
IPC$
IPC
IPC Service (Public Test Server)
ADMIN$
IPC
IPC Service (Public Test Server)
Anonymous login successful
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.0.10-1.4E.9]
Server
--------RHEL4B
WINXP
Comment
------Public Test Server
Workgroup
--------WORKGROUP
Master
------WINXP
Comment
------IPC Service (Samba 3.5.11)
Server=[Samba 3.5.11]
Server
---------
Comment
-------
Workgroup
--------LINUXTR
WORKGROUP
Master
------DEBIAN6
UBU1110
Type
---Disk
Comment
------Default share
124
IPC$
ADMIN$
...
IPC
Disk
Remote IPC
Remote Admin
10.4. /usr/bin/smbtree
Another useful tool to troubleshoot Samba or simply to browse the SMB network is smbtree.
In its simplest form, smbtree will do an anonymous browsing on the local subnet. displaying
all SMB computers and (if authorized) their shares.
Let's take a look at two screenshots of smbtree in action (with blank password). The first
one is taken immediately after booting four different computers (one MS Windows 2000,
one MS Windows xp, one MS Windows 2003 and one RHEL 4 with Samba 3.0.10).
[paul@RHEL4b ~]$ smbtree
Password:
WORKGROUP
PEGASUS
\\WINXP
\\RHEL4B
Pegasus Domain Member Server
Error connecting to 127.0.0.1 (Connection refused)
cli_full_connection: failed to connect to RHEL4B<20> (127.0.0.1)
\\HM2003
[paul@RHEL4b ~]$
The information displayed in the previous screenshot looks incomplete. The browsing
elections are still ongoing, the browse list is not yet distributed to all clients by the (to be
elected) browser master. The next screenshot was taken about one minute later. And it shows
even less.
[paul@RHEL4b ~]$ smbtree
Password:
WORKGROUP
\\W2000
[paul@RHEL4b ~]$
So we wait a while, and then run smbtree again, this time it looks a lot nicer.
[paul@RHEL4b ~]$ smbtree
Password:
WORKGROUP
\\W2000
PEGASUS
\\WINXP
\\RHEL4B
Pegasus Domain Member Server
\\RHEL4B\ADMIN$
IPC Service (Pegasus Domain Member Server)
\\RHEL4B\IPC$
IPC Service (Pegasus Domain Member Server)
\\RHEL4B\domaindata
Active Directory users only
\\HM2003
[paul@RHEL4b ~]$ smbtree --version
Version 3.0.10-1.4E.9
[paul@RHEL4b ~]$
I added the version number of smbtree in the previous screenshot, to show you the difference
when using the latest version of smbtree (below a screenshot taken from Ubuntu Feisty
Fawn). The latest version shows a more complete overview of machines and shares.
paul@laika:~$ smbtree --version
Version 3.0.24
125
paul@laika:~$ smbtree
Password:
WORKGROUP
\\W2000
\\W2000\firstshare
\\W2000\C$
Default share
\\W2000\ADMIN$
Remote Admin
\\W2000\IPC$
Remote IPC
PEGASUS
\\WINXP
cli_rpc_pipe_open: cli_nt_create failed on pipe \srvsvc to machine WINXP.
Error was NT_STATUS_ACCESS_DENIED
\\RHEL4B
Pegasus Domain Member Server
\\RHEL4B\ADMIN$
IPC Service (Pegasus Domain Member Server)
\\RHEL4B\IPC$
IPC Service (Pegasus Domain Member Server)
\\RHEL4B\domaindata
Active Directory users only
\\HM2003
cli_rpc_pipe_open: cli_nt_create failed on pipe \srvsvc to machine HM2003.
Error was NT_STATUS_ACCESS_DENIED
paul@laika:~$
The previous screenshot also provides useful errors on why we cannot see shared info on
computers winxp and w2003. Let us try the old smbtree version on our RHEL server, but
this time with Administrator credentials (which are the same on all computers).
[paul@RHEL4b ~]$ smbtree -UAdministrator%Stargate1
WORKGROUP
\\W2000
PEGASUS
\\WINXP
\\WINXP\C$
Default share
\\WINXP\ADMIN$
Remote Admin
\\WINXP\share55
\\WINXP\IPC$
Remote IPC
\\RHEL4B
Pegasus Domain Member Server
\\RHEL4B\ADMIN$
IPC Service (Pegasus Domain Member Server)
\\RHEL4B\IPC$
IPC Service (Pegasus Domain Member Server)
\\RHEL4B\domaindata
Active Directory users only
\\HM2003
\\HM2003\NETLOGON
Logon server share
\\HM2003\SYSVOL
Logon server share
\\HM2003\WSUSTemp
A network share used by Local Publishing ...
\\HM2003\ADMIN$
Remote Admin
\\HM2003\tools
\\HM2003\IPC$
Remote IPC
\\HM2003\WsusContent
A network share to be used by Local ...
\\HM2003\C$
Default share
[paul@RHEL4b ~]$
As you can see, this gives a very nice overview of all SMB computers and their shares.
After a short while, the changed option is visible on the Microsoft computers.
126
Then edit the inetd.conf or change the disable = yes line in /etc/xinetd.d/swat to disable
= no.
[root@RHEL4b samba]# cat /etc/xinetd.d/swat
# default: off
# description: SWAT is the Samba Web Admin Tool. Use swat \
#
to configure your Samba server. To use SWAT, \
#
connect to port 901 with your favorite web browser.
service swat
{
port
= 901
socket_type
= stream
wait
= no
only_from
= 127.0.0.1
user
= root
server
= /usr/sbin/swat
log_on_failure += USERID
disable
= no
}
[root@RHEL4b samba]# /etc/init.d/xinetd restart
Stopping xinetd:
[ OK ]
Starting xinetd:
[ OK ]
[root@RHEL4b samba]#
Change the only from value to enable swat from remote computers. This examples shows
how to provide swat access to all computers in a /24 subnet.
[root@RHEL53 xinetd.d]# grep only /etc/xinetd.d/swat
only_from = 192.168.1.0/24
Be careful when using SWAT, it erases all your manually edited comments in smb.conf.
127
128
9. Browse the network with net view, smbtree and with Windows Explorer.
on Linux: smbtree
on Windows: net view (and WindowsKey + e)
10. Change the "Server String" parameter in smb.conf. How long does it take before you see
the change (net view, smbclient, My Network Places,...) ?
vi /etc/samba/smb.conf
(should take only seconds when restarting samba)
11. Will restarting Samba after a change to smb.conf speed up the change ?
yes
129
12. Which computer is the master browser master in your workgroup ? What is the master
browser ?
The computer that won the elections.
This machine will make the list of computers in the network
13. If time permits (or if you are waiting for other students to finish this practice), then install
a sniffer (wireshark) and watch the browser elections.
On ubuntu: sudo aptitude install wireshark
then: sudo wireshark, select interface
130
131
You might have noticed the line with security = share. This line sets the default security
mode for our samba server. Setting the security mode to share will allow clients (smbclient,
any windows, another Samba server, ...) to provide a password for each share. This is one
way of using the SMB/CIFS protocol. The other way (called user mode) will allow the
client to provide a username/password combination, before the server knows which share
the client wants to access.
132
It doesn't really matter which Linux distribution you use. Below the same config on Debian
6, as good as identical.
root@debian6:~# cat /etc/samba/smb.conf
[global]
workgroup = LINUXTR
netbios name = DEBIAN6
security = share
[roshare1]
path = /srv/samba/readonly
read only = yes
guest ok = yes
[
[
[
[
OK
OK
OK
OK
]
]
]
]
Comment
------Samba 3.0.33-3.7.el5
Workgroup
--------WORKGROUP
Master
------W2003EE
133
Then we test looking at the contents of the share, and reading the files.
C:\>dir k:
Volume in drive K is pubread
Volume Serial Number is 0C82-11F2
Directory of K:\
21/01/2009
21/01/2009
21/01/2009
21/01/2009
05:49
<DIR>
.
05:49
<DIR>
..
05:49
17 summer.txt
05:49
18 winter.txt
2 File(s)
35 bytes
2 Dir(s) 13.496.242.176 bytes free
134
And then connect to this machine with netcat from any Linux computer. You end up with
a cmd.exe prompt inside your Linux shell.
paul@laika:~$ nc 192.168.1.38 23
Microsoft Windows [Version 5.2.3790]
(C) Copyright 1985-2003 Microsoft Corp.
C:\>net use k: /delete
net use k: /delete
k: was deleted successfully.
135
136
5. Verify from your own and from another computer (smbclient, net use, ...) that the share
is accessible for reading.
On Linux: smbclient -NL 127.0.0.1
On Windows Explorer: browse to My Network Places
On Windows cmd.exe: net use L: //studentx/readonly
137
138
And this is an example of using the read only parameter to give write access to a share.
read only = no
139
06:11
<DIR>
.
06:11
<DIR>
..
06:16
6 hoi.txt
1 File(s)
6 bytes
2 Dir(s) 13.496.238.080 bytes free
140
141
2. Make sure everyone can read and write files, test writing with smbclient and from a
Microsoft computer.
to test writing with smbclient:
142
143
13.3. /usr/bin/smbpasswd
The sambanobody user account that we created in the previous examples is not yet used
by samba. It just owns the files and directories that we created for our shares. The goal of
this section is to force ownership of files created through the samba share to belong to our
sambanobody user. Remember, our server is still accessible to everyone, nobody needs to
know this user account or password. We just want a clean Linux server.
To accomplish this, we first have to tell Samba about this user. We can do this by adding
the account to smbpasswd.
[root@RHEL52 samba]# smbpasswd -a sambanobody
New SMB password:
Retype new SMB password:
Added user sambanobody.
13.4. /etc/samba/smbpasswd
To find out where Samba keeps this information (for now), use smbd -b. The
PRIVATE_DIR variable will show you where the smbpasswd database is located.
[root@RHEL52 samba]# smbd -b | grep PRIVATE
PRIVATE_DIR: /etc/samba
[root@RHEL52 samba]# ls -l smbpasswd
-rw------- 1 root root 110 Jan 21 06:19 smbpasswd
You can use a simple cat to see the contents of the smbpasswd database. The sambanobody
user does have a password (it is secret).
[root@RHEL52 samba]# cat smbpasswd
144
]:LCT-4976B05B:
When you reconnect to the share and write a file, then this sambanobody user will own the
newly created file (and nobody needs to know the password).
145
146
3. Create a writable shared directory and use the "force user" and "force group" directives
to force ownership of files.
[userwrite]
path = /srv/samba/userwrite
comment = everyone writes files owned by smbguest
read only = no
guest ok = yes
force user = smbguest
force group = smbguest
4. Test the working of force user with smbclient, net use and Windows Explorer.
ls -l /srv/samba/userwrite (and verify ownership)
147
148
samba authentication
149
samba authentication
[global]
workgroup = WORKGROUP
netbios name = TEACHER0
server string = Samba File Server
security = user
The next screenshot is martina on a Windows 2000 computer, she succeeds in writing her
files, but fails to overwrite the file from serena.
C:\>net use k: \\teacher0\authwrite stargate /user:martina
The command completed successfully.
C:\>k:
K:\>echo greetings from martina > Martina.txt
K:\>echo test overwrite > serena.txt
Access is denied.
150
samba authentication
Then we test with the correct password, and verify that we can access a file on the share.
[root@RHEL52 samba]# smbclient //teacher0/authwrite -U martina stargate
Domain=[TEACHER0] OS=[Unix] Server=[Samba 3.0.33-3.7.el5]
smb: \> more serena.txt
getting file \serena.txt of size 14 as /tmp/smbmore.QQfmSN (6.8 kb/s)
one
two
three
smb: \> q
samba]# ls -l /srv/samba/authwrite/
martina martina 0 Jan 21 20:06 martina.txt
serena serena 14 Jan 21 20:06 serena.txt
serena serena
6 Jan 21 20:09 ser.txt
14.8.2. NT_STATUS_LOGON_FAILURE
You can get NT_STATUS_LOGON_FAILURE when you type the wrong password or
when you type an unexisting username.
[root@RHEL52 samba]# smbclient //teacher0/authwrite -U martina STARGATE
session setup failed: NT_STATUS_LOGON_FAILURE
151
samba authentication
152
samba authentication
153
samba authentication
[authwrite]
path = /srv/samba/authwrite
comment = authenticated users only
read only = no
guest ok = no
3. Use smbclient and a windows computer to access your share, use more than one user
account (windows requires a logoff/logon for this).
on Linux: smbclient //studentX/authwrite -U user1 password
on windows net use p: \\studentX\authwrite password /user:user2
154
155
156
15.3.2. browsable
Setting the browseable = no directive will hide shares from My Network Places. But it will
not prevent someone from accessing the share (when the name of the share is known).
Note that browsable and browseable are both correct syntax.
[pubread]
path = /srv/samba/readonly
comment = files to read
read only = yes
guest ok = yes
browseable = no
157
guest ok = No
create mask = 640
directory mask = 750
158
159
4. Even though the sales share is writable, ann should only have read access.
read list = ann
5. Even though the budget share is read only, sandra should also have write access.
write list = sandra
6. Limit one shared directory to the 192.168.1.0/24 subnet, and another share to the two
computers with ip-addresses 192.168.1.33 and 172.17.18.19.
hosts allow = 192.168.1.
hosts allow = 192.168.1.33, 172.17.18.19
7. Make sure the computer with ip 192.168.1.203 cannot access the budget share.
hosts deny = 192.168.1.203
8. Make sure (on the budget share) that users can see only files and directories to which
they have access.
hide unreadable = yes
9. Make sure the sales share is not visible when browsing the network.
browsable = no
10. All files created in the sales share should have 640 permissions or less.
create mask = 640
11. All directories created in the budget share should have 750 permissions or more.
force directory mode = 750
12. Permissions for files on the sales share should never be set more than 664.
security mask = 750
13. Permissions for files on the budget share should never be set less than 500.
force security directory mask = 500
14. If time permits (or if you are waiting for other students to finish this practice), then
combine the "read only" and "writable" statements to check which one has priority.
160
15. If time permits then combine "read list", "write list", "hosts allow" and "hosts deny".
Which of these has priority ?
161
162
163
[
[
OK
OK
]
]
We can verify in the aduc (Active Directory Users and Computers) that a computer account
is created for this samba server.
164
16.3. winbind
16.3.1. adding winbind to nsswitch.conf
The winbind daemon is talking with the Active Directory domain.
We need to update the /etc/nsswitch.conf file now, so user group and host names can be
resolved against the winbind daemon.
[root@RHEL52 samba]# vi /etc/nsswitch.conf
[root@RHEL52 samba]# grep winbind /etc/nsswitch.conf
passwd:
files winbind
group:
files winbind
hosts:
files dns winbind
[
[
OK
OK
]
]
OK
16.4. wbinfo
16.4.1. verify the trust
You can use wbinfo -t to verify the trust between your samba server and Active Directory.
165
16.5. getent
We can use getent to verify that winbindd is working and actually adding the Active
directory users to /etc/passwd.
166
If the user already exists locally, then the local user account is shown. This is because
winbind is configured in /etc/nsswitch.conf after files.
[root@RHEL52 ~]# getent passwd paul
paul:x:500:500:Paul Cobbaut:/home/paul:/bin/bash
All the Active Directory users can now easily connect to the Samba share. Files created by
them, belong to them.
167
168
169
17.1.3. Samba 3
Samba 3 can act as a domain controller in its own domain. In a Windows NT4 domain, with
one Windows NT4 PDC and zero or more BDC's, Samba 3 can only be a member server.
The same is valid for Samba 3 in an Active Directory Domain. In short, a Samba 3 domain
controller can not share domain control with Windows domain controllers.
17.1.4. Samba 4
Samba 4 can be a domain controller in an Active Directory domain, including managing
group policies. As of this writing, Samba 4 is not released for production!
170
17.4.1. security
The security must be set to user (which is the default). This mode will make samba control
the user accounts, so it will allow samba to act as a domain controller.
security = user
17.4.2. os level
A samba server is the most stable computer in the network, so it should win all browser
elections (os level above 32) to become the browser master
os level = 33
171
172
[football]
comment = Information about football
path = /srv/samba/football
valid users = @ntfootball
read only = No
samba]#
samba]#
samba]#
samba]#
groupadd
groupadd
groupadd
groupadd
ntadmins
ntsports
ntfootball
nttennis
This enables us to add group membership info to some new users for our samba domain.
Don't forget to give them a password.
[root@RHEL52
[root@RHEL52
[root@RHEL52
[root@RHEL52
[root@RHEL52
[root@RHEL52
[root@RHEL52
samba]#
samba]#
samba]#
samba]#
samba]#
samba]#
samba]#
useradd
useradd
useradd
useradd
useradd
useradd
useradd
-m
-m
-m
-m
-m
-m
-m
-G
-G
-G
-G
-G
-G
-G
ntadmins Administrator
ntsports,nttennis venus
ntsports,nttennis kim
ntsports,nttennis jelena
ntsports,ntfootball figo
ntsports,ntfootball ronaldo
ntsports,ntfootball pfaff
It is always safe to verify creation of users, groups and passwords in /etc/passwd, /etc/shadow
and /etc/group.
[root@RHEL52 samba]# tail -11 /etc/group
ntadmins:x:507:Administrator
ntsports:x:508:venus,kim,jelena,figo,ronaldo,pfaff
ntfootball:x:509:figo,ronaldo,pfaff
nttennis:x:510:venus,kim,jelena
Administrator:x:511:
venus:x:512:
kim:x:513:
jelena:x:514:
figo:x:515:
ronaldo:x:516:
pfaff:x:517:
17.8. tdbsam
Next we must make these users known to samba with the smbpasswd tool. When you add
the first user to tdbsam, the file /etc/samba/passdb.tdb will be created.
[root@RHEL52 samba]# smbpasswd -a root
New SMB password:
173
Adding all the other users generates less output, because tdbsam is already created.
[root@RHEL4b samba]# smbpasswd -a root
New SMB password:
Retype new SMB password:
Added user root.
To be able to create the account, you will need to provide credentials of an account with
the permission to create accounts (by default only root can do this on Linux). And we will
have to tell Samba how to to this, by adding an add machine script to the global section
of smb.conf.
add machine script = /usr/sbin/useradd -s /bin/false -d /home/nobody %u
You can now join a Microsoft computer to the sports domain (with the root user). After
reboot of the Microsoft computer, you will be able to logon with Administrator (password
Stargate1), but you will get an error about your roaming profile. We will fix this in the next
section.
When joining the samba domain, you have to enter the credentials of a Linux account that
can create users (usually only root can do this). If the Microsoft computer complains with
The parameter is incorrect, then you possibly forgot to add the add machine script.
174
logon home =
logon path =
Microsoft computers store a lot of User Metadata and application data in a user profile.
Making this profile available on the network will enable users to keep their Desktop and
Application settings across computers. User profiles on the network are called roaming
profiles or roving profiles. The Samba domain controller can manage these profiles. First
we need to add the relevant section in smb.conf.
[Profiles]
comment = User Profiles
path = /srv/samba/profiles
readonly = No
profile acls = Yes
Besides the share section, we also need to set the location of the profiles share (this can be
another Samba server) in the global section.
logon path = \\%L\Profiles\%U
The %L variable is the name of this Samba server, the %U variable translates to the
username. After adding a user to smbpasswd and letting the user log on and off, the profile
of the user will look like this.
[root@RHEL4b samba]# ll /srv/samba/profiles/Venus/
total 568
drwxr-xr-x 4 Venus Venus
4096 Jul 5 10:03 Application Data
drwxr-xr-x 2 Venus Venus
4096 Jul 5 10:03 Cookies
drwxr-xr-x 3 Venus Venus
4096 Jul 5 10:03 Desktop
drwxr-xr-x 3 Venus Venus
4096 Jul 5 10:03 Favorites
drwxr-xr-x 4 Venus Venus
4096 Jul 5 10:03 My Documents
drwxr-xr-x 2 Venus Venus
4096 Jul 5 10:03 NetHood
-rwxr--r-- 1 Venus Venus 524288 Jul 5 2007 NTUSER.DAT
-rwxr--r-- 1 Venus Venus
1024 Jul 5 2007 NTUSER.DAT.LOG
-rw-r--r-- 1 Venus Venus
268 Jul 5 10:03 ntuser.ini
drwxr-xr-x 2 Venus Venus
4096 Jul 5 10:03 PrintHood
drwxr-xr-x 2 Venus Venus
4096 Jul 5 10:03 Recent
drwxr-xr-x 2 Venus Venus
4096 Jul 5 10:03 SendTo
drwxr-xr-x 3 Venus Venus
4096 Jul 5 10:03 Start Menu
drwxr-xr-x 2 Venus Venus
4096 Jul 5 10:03 Templates
175
[root@RHEL4b samba]#
Does this mean that Venus can access the tennis and the sports shares ? Yes, all access
works fine on the Samba server. But the nttennis group is not available on the windows
machines. To make the groups available on windows (like in the ntfs security tab of files
and folders), we have to map unix groups to windows groups. To do this, we use the net
groupmap command.
[root@RHEL4b samba]# net groupmap add ntgroup="tennis" unixgroup=nttennis type=d
No rid or sid specified, choosing algorithmic mapping
Successully added group tennis to the mapping db
[root@RHEL4b samba]# net groupmap add ntgroup="football" unixgroup=ntfootball type=d
No rid or sid specified, choosing algorithmic mapping
Successully added group football to the mapping db
[root@RHEL4b samba]# net groupmap add ntgroup="sports" unixgroup=ntsports type=d
No rid or sid specified, choosing algorithmic mapping
Successully added group sports to the mapping db
[root@RHEL4b samba]#
Now you can use the Samba groups on all NTFS volumes on members of the domain.
Then copy the scripts to the netlogon share, and add the following parameter to smb.conf.
logon script = start.bat
176
177
178
179
Then we can use the provision script to setup our realm. I used booi.schot as domain name
(instead of example.com).
./setup/provision --realm=BOOI.SCHOT --domain=BOOI --adminpass=stargate \
--server-role='domain controller'
I checked that bind (and bind-chroot) were installed (yes), so copied the srv records
cp booi.schot.zone /var/named/chroot/etc/
180
restart bind (named!), then tested dns with dig, this works (stripped screenshot!)
[root@RHEL52 private]# dig _ldap._tcp.dc._msdcs.booi.schot SRV @localhost
; (1 server found)
;; global options: printcmd
;; Got answer:
;; -HEADER- opcode: QUERY, status: NXDOMAIN, id: 58186
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;_ldap._tcp.dc._msdcs.booi.schot. IN SRV
;; AUTHORITY SECTION:
.
10800 IN SOA A.ROOT-SERVERS.NET....
;;
;;
;;
;;
[root@RHEL52 private]#
181
Table of Contents
19. introduction to SELinux .................................................................................................
19.1. selinux modes ......................................................................................................
19.2. logging ...............................................................................................................
19.3. activating selinux ..................................................................................................
19.4. getenforce ............................................................................................................
19.5. setenforce ............................................................................................................
19.6. sestatus ...............................................................................................................
19.7. policy .................................................................................................................
19.8. /etc/selinux/config .................................................................................................
19.9. DAC or MAC ......................................................................................................
19.10. ls -Z .................................................................................................................
19.11. -Z .....................................................................................................................
19.12. /selinux ..............................................................................................................
19.13. identity ..............................................................................................................
19.14. role ...................................................................................................................
19.15. type (or domain) .................................................................................................
19.16. security context ...................................................................................................
19.17. transition ...........................................................................................................
19.18. extended attributes ...............................................................................................
19.19. process security context ........................................................................................
19.20. chcon ................................................................................................................
19.21. an example ........................................................................................................
19.22. setroubleshoot .....................................................................................................
19.23. booleans ............................................................................................................
183
184
185
185
185
186
186
187
187
187
188
188
188
189
189
189
190
191
191
192
192
192
193
195
197
184
introduction to SELinux
19.2. logging
Verify that syslog is running and activated on boot to enable logging of deny messages in
/var/log/messages.
[root@rhel55 ~]# chkconfig --list syslog
syslog
0:off 1:off 2:on 3:on 4:on 5:on 6:off
Verify that auditd is running and activated on boot to enable logging of easier to read
messages in /var/log/audit/audit.log.
[root@rhel55 ~]# chkconfig --list auditd
auditd
0:off 1:off 2:on 3:on 4:on 5:on 6:off
If not activated, then run chkconfig --levels 2345 auditd on and service auditd start.
[root@rhel55 ~]# service auditd status
auditd (pid 1660) is running...
[root@rhel55 ~]# service syslog status
syslogd (pid 1688) is running...
klogd (pid 1691) is running...
The /var/log/messages log file will tell you that selinux is disabled.
root@deb503:~# grep -i selinux /var/log/messages
Jun 25 15:59:34 deb503 kernel: [
0.084083] SELinux:
Disabled at boot.
Or that it is enabled.
root@deb503:~# grep SELinux /var/log/messages | grep -i Init
Jun 25 15:09:52 deb503 kernel: [
0.084094] SELinux: Initializing.
185
introduction to SELinux
19.4. getenforce
Use getenforce to verify whether selinux is enforced, disabled or permissive.
[root@rhel55 ~]# getenforce
Permissive
The /selinux/enforce file contains 1 when enforcing, and 0 when permissive mode is ative.
root@fedora13 ~# cat /selinux/enforce
1root@fedora13 ~#
19.5. setenforce
You can use setenforce to switch between the Permissive or the Enforcing state once
selinux is activated..
[root@rhel55
[root@rhel55
Enforcing
[root@rhel55
[root@rhel55
Permissive
~]# setenforce 1
~]# getenforce
~]# setenforce 0
~]# getenforce
~]#
186
introduction to SELinux
19.6. sestatus
You can see the current selinux status and policy with the sestatus command.
[root@rhel55 ~]# sestatus
SELinux status:
SELinuxfs mount:
Current mode:
Mode from config file:
Policy version:
Policy from config file:
enabled
/selinux
permissive
permissive
21
targeted
19.7. policy
Most Red Hat server will have the targeted policy. Only NSA/FBI/CIA/DOD/HLS use the
mls policy.
The targted policy will protect hundreds of processes, but lets other processes run
'unconfined' (= they can do anything).
19.8. /etc/selinux/config
The main configuration file for selinux is /etc/selinux/config. When in permissive mode,
the file looks like this.
The targeted policy is selected in /etc/selinux/config.
[root@centos65 ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#
enforcing - SELinux security policy is enforced.
#
permissive - SELinux prints warnings instead of enforcing.
#
disabled - SELinux is fully disabled.
SELINUX=permissive
# SELINUXTYPE= type of policy in use. Possible values are:
#
targeted - Only targeted network daemons are protected.
#
strict - Full SELinux protection.
SELINUXTYPE=targeted
187
introduction to SELinux
19.10. ls -Z
To see the DAC permissions on a file, use ls -l to display user and group owner and
permissions.
For MAC permissions there is new -Z option added to ls. The output shows that file in /root
have a XXXtype of admin_home_t.
[root@centos65 ~]# ls
-rw-------. root root
-rw-r--r--. root root
-rw-r--r--. root root
-Z
system_u:object_r:admin_home_t:s0 anaconda-ks.cfg
system_u:object_r:admin_home_t:s0 install.log
system_u:object_r:admin_home_t:s0 install.log.syslog
19.11. -Z
There are also some other tools with the -Z switch:
mkdir -Z
cp -Z
ps -Z
netstat -Z
...
188
introduction to SELinux
19.12. /selinux
When selinux is active, there is a new virtual file system named /selinux. (You can compare
it to /proc and /dev.)
[root@centos65
total 0
-rw-rw-rw-. 1
dr-xr-xr-x. 2
dr-xr-xr-x. 2
-rw-r--r--. 1
dr-xr-xr-x. 83
--w-------. 1
-rw-rw-rw-. 1
-rw-rw-rw-. 1
-r--r--r--. 1
--w-------. 1
-rw-r--r--. 1
dr-xr-xr-x. 2
-rw-------. 1
-rw-rw-rw-. 1
-r--r--r--. 1
crw-rw-rw-. 1
-r--------. 1
dr-xr-xr-x. 2
-r--r--r--. 1
-r--r--r--. 1
-rw-rw-rw-. 1
-r--r--r--. 1
-rw-rw-rw-. 1
~]# ls -l /selinux/
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
0 Apr 12 19:40 access
root
0 Apr 12 19:40 avc
root
0 Apr 12 19:40 booleans
root
0 Apr 12 19:40 checkreqprot
root
0 Apr 12 19:40 class
root
0 Apr 12 19:40 commit_pending_bools
root
0 Apr 12 19:40 context
root
0 Apr 12 19:40 create
root
0 Apr 12 19:40 deny_unknown
root
0 Apr 12 19:40 disable
root
0 Apr 12 19:40 enforce
root
0 Apr 12 19:40 initial_contexts
root
0 Apr 12 19:40 load
root
0 Apr 12 19:40 member
root
0 Apr 12 19:40 mls
root 1, 3 Apr 12 19:40 null
root
0 Apr 12 19:40 policy
root
0 Apr 12 19:40 policy_capabilities
root
0 Apr 12 19:40 policyvers
root
0 Apr 12 19:40 reject_unknown
root
0 Apr 12 19:40 relabel
root
0 Apr 12 19:40 status
root
0 Apr 12 19:40 user
Although some files in /selinux appear wih size 0, they often contain a boolean value. Check
/selinux/enforce to see if selinux is running in enforced mode.
[root@RHEL5 ~]# ls -l /selinux/enforce
-rw-r--r-- 1 root root 0 Apr 29 08:21 /selinux/enforce
[root@RHEL5 ~]# echo $(cat /selinux/enforce)
1
19.13. identity
The SELinux Identity of a user is distinct from the user ID. An identity is part of a security
context, and (via domains) determines what you can do. The screenshot shows user root
having identity user_u.
[root@rhel55 ~]# id -Z
user_u:system_r:unconfined_t
19.14. role
The selinux role defines the domains that can be used. A role is denied to enter a domain,
unless the role is explicitely authorized to do so.
189
introduction to SELinux
0:00 /sbin/init
0:00
0:00
0:00
0:00
0:00
0:00
/sbin/mingetty
/sbin/mingetty
/sbin/mingetty
/sbin/mingetty
/sbin/mingetty
/sbin/mingetty
/dev/tty1
/dev/tty2
/dev/tty3
/dev/tty4
/dev/tty5
/dev/tty6
The selinux type is similar to an selinux domain, but refers to directories and files instead
of processes.
Hundreds of binaries also have a type:
[root@centos65 sbin]#
-rwxr-xr-x. root root
-rwxr-xr-x. root root
-rwxr-xr-x. root root
-rwxr-x---. root root
-rwxr-x---. root root
-rwxr-x---. root root
You can also get a list of ports that are managed by SELinux:
[root@centos65 ~]# semanage port -l | tail
xfs_port_t
tcp
7100
xserver_port_t
tcp
6000-6150
zabbix_agent_port_t
tcp
10050
zabbix_port_t
tcp
10051
zarafa_port_t
tcp
236, 237
zebra_port_t
tcp
2600-2604, 2606
zebra_port_t
udp
2600-2604, 2606
zented_port_t
tcp
1229
zented_port_t
udp
1229
zope_port_t
tcp
8021
190
introduction to SELinux
The ls -Z command shows the security context for a file in the form identity:role:type.
[paul@RHEL5 ~]$ ls -Z test
-rw-rw-r-- paul paul user_u:object_r:user_home_t
test
The security context for processes visible in /proc defines both the type (of the file in /proc)
and the domain (of the running process). Let's take a look at the init process and /proc/1/ .
The init process runs in domain init_t.
[root@RHEL5 ~]# ps -ZC init
LABEL
system_u:system_r:init_t
PID TTY
1 ?
TIME CMD
00:00:01 init
The /proc/1/ directory, which identifies the init process, has type init_t.
[root@RHEL5 ~]# ls -Zd /proc/1/
dr-xr-xr-x root root system_u:system_r:init_t
/proc/1/
It is not a coincidence that the domain of the init process and the type of /proc/1/ are both
init_t.
Don't try to use chcon on /proc! It will not work.
19.17. transition
An selinux transition (aka an selinux labelling) determines the security context that will be
assigned. A transition of process domains is used when you execute a process. A transition
of file type happens when you create a file.
An example of file type transition.
[pol@centos65 ~]$ touch test /tmp/test
[pol@centos65 ~]$ ls -Z test
-rw-rw-r--. pol pol unconfined_u:object_r:user_home_t:s0 test
[pol@centos65 ~]$ ls -Z /tmp/test
-rw-rw-r--. pol pol unconfined_u:object_r:user_tmp_t:s0 /tmp/test
191
introduction to SELinux
home]# ls
paul paul
root root
root root
home]# ls
paul paul
root root
root root
home]#
--context
system_u:object_r:user_home_dir_t paul
user_u:object_r:user_home_dir_t project42
user_u:object_r:user_home_dir_t project55
-Z
system_u:object_r:user_home_dir_t paul
user_u:object_r:user_home_dir_t project42
user_u:object_r:user_home_dir_t project55
TIME CMD
00:00:00 mingetty
00:00:00 mingetty
19.20. chcon
Use chcon to change the selinux security context.
This example shows how to use chcon to change the type of a file.
[root@rhel55 ~]#
-rw-r--r-- root
2.txt
[root@rhel55 ~]#
[root@rhel55 ~]#
-rw-r--r-- root
ls -Z /var/www/html/test42.txt
root user_u:object_r:httpd_sys_content_t /var/www/html/test4\
chcon -t samba_share_t /var/www/html/test42.txt
ls -Z /var/www/html/test42.txt
root user_u:object_r:samba_share_t
/var/www/html/test42.txt
192
introduction to SELinux
19.21. an example
The Apache2 webserver is by default targeted with SELinux. The next screenshot shows
that any file created in /var/www/html will by default get the httpd_sys_content_t type.
[root@centos65 ~]# touch /var/www/html/test42.txt
[root@centos65 ~]# ls -Z /var/www/html/test42.txt
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/h\
tml/test42.txt
[
[
OK
OK
]
]
Why does this work ? Because Apache2 runs in the httpd_t domain and the files in /var/
www/html have the httpd_sys_content_t type.
[root@centos65 ~]# ps -ZC httpd | head -4
LABEL
PID TTY
unconfined_u:system_r:httpd_t:s0 1666 ?
unconfined_u:system_r:httpd_t:s0 1668 ?
unconfined_u:system_r:httpd_t:s0 1669 ?
193
TIME
00:00:00
00:00:00
00:00:00
CMD
httpd
httpd
httpd
introduction to SELinux
So let's set SELinux to enforcing and change the type of this file.
[root@centos65 ~]# chcon -t samba_share_t /var/www/html/test42.txt
[root@centos65 ~]# ls -Z /var/www/html/test42.txt
-rw-r--r--. root root unconfined_u:object_r:samba_share_t:s0 /var/www/html/t\
est42.txt
[root@centos65 ~]# setenforce 1
[root@centos65 ~]# getenforce
Enforcing
There are two possibilities now: either it works, or it fails. It works when selinux is in
permissive mode, it fails when in enforcing mode.
[root@centos65 ~]# wget http://localhost/test42.txt
--2014-04-12 21:05:02-- http://localhost/test42.txt
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:80... connected.
HTTP request sent, awaiting response... 403 Forbidden
2014-04-12 21:05:02 ERROR 403: Forbidden.
194
introduction to SELinux
19.22. setroubleshoot
The log file above was not very helpful, but these two packages can make your life much
easier.
[root@centos65 ~]# yum -y install setroubleshoot setroubleshoot-server
[FAILED]
[ OK ]
The /var/log/audit/ is still not out best friend, but take a look at /var/log/messages.
[root@centos65 ~]# tail -2 /var/log/messages
Apr 12 21:44:16 centos65 setroubleshoot: SELinux is preventing /usr/sbin/h\
ttpd from getattr access on the file /var/www/html/test42.txt. For complete \
SELinux messages. run sealert -l b2a84386-54c1-4344-96fb-dcf969776696
Apr 12 21:44:16 centos65 setroubleshoot: SELinux is preventing /usr/sbin/h\
ttpd from getattr access on the file /var/www/html/test42.txt. For complete \
SELinux messages. run sealert -l b2a84386-54c1-4344-96fb-dcf969776696
*********************
195
introduction to SELinux
We follow the friendly advice and try again to download our file:
[root@centos65 ~]# /sbin/restorecon -v /var/www/html/test42.txt
/sbin/restorecon reset /var/www/html/test42.txt context unconfined_u:objec\
t_r:samba_share_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
[root@centos65 ~]# wget http://localhost/test42.txt
--2014-04-12 21:54:03-- http://localhost/test42.txt
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:80... connected.
HTTP request sent, awaiting response... 200 OK
It works!
196
introduction to SELinux
19.23. booleans
Booleans are on/off switches
[root@centos65 ~]# getsebool -a | head
abrt_anon_write --> off
abrt_handle_event --> off
allow_console_login --> on
allow_cvs_read_shadow --> off
allow_daemons_dump_core --> on
allow_daemons_use_tcp_wrapper --> off
allow_daemons_use_tty --> on
allow_domain_fd_use --> on
allow_execheap --> off
allow_execmem --> on
197
Table of Contents
20. git ................................................................................................................................ 200
20.1. practice: git .......................................................................................................... 201
199
200
git
201
Table of Contents
21. Introduction to ipv6 .......................................................................................................
21.1. about ipv6 ...........................................................................................................
21.2. network id and host id ...........................................................................................
21.3. host part generation ...............................................................................................
21.4. ipv4 mapped ipv6 address ......................................................................................
21.5. link local addresses ...............................................................................................
21.6. unique local addresses ...........................................................................................
21.7. globally unique unicast addresses .............................................................................
21.8. 6to4 ....................................................................................................................
21.9. ISP .....................................................................................................................
21.10. non routable addresses .........................................................................................
21.11. ping6 ................................................................................................................
21.12. Belgium and ipv6 ................................................................................................
21.13. other websites .....................................................................................................
21.14. 6to4 gateways .....................................................................................................
21.15. ping6 and dns .....................................................................................................
21.16. ipv6 and tcp/http .................................................................................................
21.17. ipv6 PTR record .................................................................................................
21.18. 6to4 setup on Linux .............................................................................................
203
204
205
205
205
206
206
206
206
206
207
207
207
208
208
210
210
210
210
210
204
Introduction to ipv6
Luckily ipv6 allows us to omit leading zeroes. Our address from above then becomes:
fe80:0:0:0:a00:27ff:fe8e:8aa8
When a 16-bit block is zero, it can be written as ::. Consecutive 16-bit blocks that are zero
can also be written as ::. So our address can from above can be shortened to:
fe80::a00:27ff:fe8e:8aa8
This :: can only occur once! The following is not a valid ipv6 address:
fe80::20:2e4f::39ac
The above address has 64 bits for the host id, theoretically allowing for 4 billion times four
billion hosts.
The localhost address looks like this with cidr:
::1/128
205
Introduction to ipv6
eth3
21.8. 6to4
6to4 is defined in rfc's 2893 and 3056 as one possible way to transition between ipv4 and
ipv6 by creating an ipv6 tunnel.
It encodes an ipv4 address in an ipv6 address that starts with 2002. For example
192.168.1.42/24 will be encoded as:
206
Introduction to ipv6
2002:c0a8:12a:18::1
You can use the command below to convert any ipv4 address to this range.
paul@ubu1010:~$ printf "2002:%02x%02x:%02x%02x:%04x::1\n" `echo 192.168.1.42/24 \
|tr "./" " "`
2002:c0a8:012a:0018::1
21.9. ISP
Should you be so lucky to get an ipv6 address from an isp, then it will start with 2001:.
21.11. ping6
Use ping6 to test connectivity between ipv6 hosts. You need to specify the interface (there
is no routing table for 'random' generated ipv6 link local addresses).
[root@fedora14 ~]# ping6 -I eth0 fe80::a00:27ff:fecd:7ffc
PING fe80::a00:27ff:fecd:7ffc(fe80::a00:27ff:fecd:7ffc) from fe80::a00:27ff:fe3c:4346 eth0: 56
64 bytes from fe80::a00:27ff:fecd:7ffc: icmp_seq=1 ttl=64 time=0.586 ms
64 bytes from fe80::a00:27ff:fecd:7ffc: icmp_seq=2 ttl=64 time=3.95 ms
64 bytes from fe80::a00:27ff:fecd:7ffc: icmp_seq=3 ttl=64 time=1.53 ms
Below a multicast ping6 that recieves replies from three ip6 hosts on the same network.
[root@fedora14 ~]# ping6 -I eth0 ff02::1
PING ff02::1(ff02::1) from fe80::a00:27ff:fe3c:4346 eth0: 56 data bytes
64 bytes from fe80::a00:27ff:fe3c:4346: icmp_seq=1 ttl=64 time=0.598 ms
64 bytes from fe80::a00:27ff:fecd:7ffc: icmp_seq=1 ttl=64 time=1.87 ms (DUP!)
64 bytes from fe80::8e7b:9dff:fed6:dff2: icmp_seq=1 ttl=64 time=535 ms (DUP!)
64 bytes from fe80::a00:27ff:fe3c:4346: icmp_seq=2 ttl=64 time=0.106 ms
64 bytes from fe80::8e7b:9dff:fed6:dff2: icmp_seq=2 ttl=64 time=1.79 ms (DUP!)
64 bytes from fe80::a00:27ff:fecd:7ffc: icmp_seq=2 ttl=64 time=2.48 ms (DUP!)
207
Introduction to ipv6
Going to the ipv6-test.com website will test whether you have a valid accessible ipv6
address.
Going to the test-ipv6.com website will also test whether you have a valid accessible ipv6
address.
208
Introduction to ipv6
209
Introduction to ipv6
210
Mask:255.255.248.0
Introduction to ipv6
tun6to4
Link encap:IPv6-in-IPv4
inet6 addr: ::81.165.101.125/128 Scope:Compat
inet6 addr: 2002:51a5:657d::1/64 Scope:Global
UP RUNNING NOARP MTU:1472 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
211
Introduction to ipv6
2002::/16 dev tun6to4 metric 1024 mtu 1472 advmss 1412 hoplimit 0
fdcb:43c1:9c18:1::/64 dev eth0 proto kernel metric 256 mtu 1500 advmss 1440 hoplimit 0
fe80::/64 dev eth0 proto kernel metric 256 mtu 1500 advmss 1440 hoplimit 0
fe80::/64 dev tun6to4 proto kernel metric 256 mtu 1472 advmss 1412 hoplimit 0
default via ::192.88.99.1 dev tun6to4 metric 1 mtu 1472 advmss 1412 hoplimit 0
root@mac:~# ping6 ipv6-test.com
PING ipv6-test.com(ipv6-test.com) 56 data bytes
64 bytes from ipv6-test.com: icmp_seq=1 ttl=57 time=42.4 ms
64 bytes from ipv6-test.com: icmp_seq=2 ttl=57 time=43.0 ms
64 bytes from ipv6-test.com: icmp_seq=3 ttl=57 time=43.5 ms
64 bytes from ipv6-test.com: icmp_seq=4 ttl=57 time=43.9 ms
64 bytes from ipv6-test.com: icmp_seq=5 ttl=57 time=45.6 ms
^C
--- ipv6-test.com ping statistics --5 packets transmitted, 5 received, 0% packet loss, time 4006ms
rtt min/avg/max/mdev = 42.485/43.717/45.632/1.091 ms
212
Part X. Appendices
Table of Contents
A. cloning ...........................................................................................................................
A.1. About cloning .......................................................................................................
A.2. About offline cloning .............................................................................................
A.3. Offline cloning example ..........................................................................................
B. License ...........................................................................................................................
214
215
215
215
215
217
Appendix A. cloning
A.1. About cloning
You can have distinct goals for cloning a server. For instance a clone can be a cold iron
backup system used for manual disaster recovery of a service. Or a clone can be created to
serve in a test environment. Or you might want to make an almost identical server. Let's take
a look at some offline and online ways to create a clone of a Linux server.
The first step is trivial. The second step is explained in the Disk Management chapter. For
the third step, you can use a combination of ssh or netcat with cp, dd, dump and restore,
tar, cpio, rsync or even cat.
The /boot partition is small but big enough. If we create an identical partition, then dd should
be a good cloning option. Suppose the / partition needs to be enlarged on the target system.
The best option then is to use a combination of dump and restore. Remember that dd copies
blocks, whereas dump/restore copies files.
The first step to do is to boot the target server with a live CD and partition the target disk.
To do this we use the Red Hat Enterprise Linux 5 install CD. At the CD boot prompt we
type "linux rescue". The cd boots into a root console where we can use fdisk to discover
and prepare the attached disks.
When the partitions are created and have their filesystem, then we can use dd to copy the /
boot partition.
215
cloning
216
Appendix B. License
GNU Free Documentation License
Version 1.3, 3 November 2008
Copyright 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.
0. PREAMBLE
The purpose of this License is to make a manual, textbook, or other
functional and useful document "free" in the sense of freedom: to
assure everyone the effective freedom to copy and redistribute it,
with or without modifying it, either commercially or noncommercially.
Secondarily, this License preserves for the author and publisher a way
to get credit for their work, while not being considered responsible
for modifications made by others.
This License is a kind of "copyleft", which means that derivative
works of the document must themselves be free in the same sense. It
complements the GNU General Public License, which is a copyleft
license designed for free software.
We have designed this License in order to use it for manuals for free
software, because free software needs free documentation: a free
program should come with manuals providing the same freedoms that the
software does. But this License is not limited to software manuals; it
can be used for any textual work, regardless of subject matter or
whether it is published as a printed book. We recommend this License
principally for works whose purpose is instruction or reference.
1. APPLICABILITY AND DEFINITIONS
This License applies to any manual or other work, in any medium, that
contains a notice placed by the copyright holder saying it can be
distributed under the terms of this License. Such a notice grants a
world-wide, royalty-free license, unlimited in duration, to use that
work under the conditions stated herein. The "Document", below, refers
to any such manual or work. Any member of the public is a licensee,
and is addressed as "you". You accept the license if you copy, modify
or distribute the work in a way requiring permission under copyright
law.
A "Modified Version" of the Document means any work containing the
Document or a portion of it, either copied verbatim, or with
modifications and/or translated into another language.
A "Secondary Section" is a named appendix or a front-matter section of
the Document that deals exclusively with the relationship of the
publishers or authors of the Document to the Document's overall
subject (or to related matters) and contains nothing that could fall
directly within that overall subject. (Thus, if the Document is in
part a textbook of mathematics, a Secondary Section may not explain
any mathematics.) The relationship could be a matter of historical
connection with the subject or with related matters, or of legal,
commercial, philosophical, ethical or political position regarding
them.
The "Invariant Sections" are certain Secondary Sections whose titles
217
License
218
License
219
License
220
License
you may not add another; but you may replace the old one, on explicit
permission from the previous publisher that added the old one.
The author(s) and publisher(s) of the Document do not by this License
give permission to use their names for publicity for or to assert or
imply endorsement of any Modified Version.
5. COMBINING DOCUMENTS
You may combine the Document with other documents released under this
License, under the terms defined in section 4 above for modified
versions, provided that you include in the combination all of the
Invariant Sections of all of the original documents, unmodified, and
list them all as Invariant Sections of your combined work in its
license notice, and that you preserve all their Warranty Disclaimers.
The combined work need only contain one copy of this License, and
multiple identical Invariant Sections may be replaced with a single
copy. If there are multiple Invariant Sections with the same name but
different contents, make the title of each such section unique by
adding at the end of it, in parentheses, the name of the original
author or publisher of that section if known, or else a unique number.
Make the same adjustment to the section titles in the list of
Invariant Sections in the license notice of the combined work.
In the combination, you must combine any sections Entitled "History"
in the various original documents, forming one section Entitled
"History"; likewise combine any sections Entitled "Acknowledgements",
and any sections Entitled "Dedications". You must delete all sections
Entitled "Endorsements".
6. COLLECTIONS OF DOCUMENTS
You may make a collection consisting of the Document and other
documents released under this License, and replace the individual
copies of this License in the various documents with a single copy
that is included in the collection, provided that you follow the rules
of this License for verbatim copying of each of the documents in all
other respects.
You may extract a single document from such a collection, and
distribute it individually under this License, provided you insert a
copy of this License into the extracted document, and follow this
License in all other respects regarding verbatim copying of that
document.
7. AGGREGATION WITH INDEPENDENT WORKS
A compilation of the Document or its derivatives with other separate
and independent documents or works, in or on a volume of a storage or
distribution medium, is called an "aggregate" if the copyright
resulting from the compilation is not used to limit the legal rights
of the compilation's users beyond what the individual works permit.
When the Document is included in an aggregate, this License does not
apply to the other works in the aggregate which are not themselves
derivative works of the Document.
If the Cover Text requirement of section 3 is applicable to these
copies of the Document, then if the Document is less than one half of
the entire aggregate, the Document's Cover Texts may be placed on
covers that bracket the Document within the aggregate, or the
electronic equivalent of covers if the Document is in electronic form.
Otherwise they must appear on printed covers that bracket the whole
aggregate.
221
License
8. TRANSLATION
Translation is considered a kind of modification, so you may
distribute translations of the Document under the terms of section 4.
Replacing Invariant Sections with translations requires special
permission from their copyright holders, but you may include
translations of some or all Invariant Sections in addition to the
original versions of these Invariant Sections. You may include a
translation of this License, and all the license notices in the
Document, and any Warranty Disclaimers, provided that you also include
the original English version of this License and the original versions
of those notices and disclaimers. In case of a disagreement between
the translation and the original version of this License or a notice
or disclaimer, the original version will prevail.
If a section in the Document is Entitled "Acknowledgements",
"Dedications", or "History", the requirement (section 4) to Preserve
its Title (section 1) will typically require changing the actual
title.
9. TERMINATION
You may not copy, modify, sublicense, or distribute the Document
except as expressly provided under this License. Any attempt otherwise
to copy, modify, sublicense, or distribute it is void, and will
automatically terminate your rights under this License.
However, if you cease all violation of this License, then your license
from a particular copyright holder is reinstated (a) provisionally,
unless and until the copyright holder explicitly and finally
terminates your license, and (b) permanently, if the copyright holder
fails to notify you of the violation by some reasonable means prior to
60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, receipt of a copy of some or all of the same material does
not give you any rights to use it.
10. FUTURE REVISIONS OF THIS LICENSE
The Free Software Foundation may publish new, revised versions of the
GNU Free Documentation License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in
detail to address new problems or concerns. See
http://www.gnu.org/copyleft/.
Each version of the License is given a distinguishing version number.
If the Document specifies that a particular numbered version of this
License "or any later version" applies to it, you have the option of
following the terms and conditions either of that specified version or
of any later version that has been published (not as a draft) by the
Free Software Foundation. If the Document does not specify a version
number of this License, you may choose any version ever published (not
as a draft) by the Free Software Foundation. If the Document specifies
222
License
that a proxy can decide which future versions of this License can be
used, that proxy's public statement of acceptance of a version
permanently authorizes you to choose that version for the Document.
11. RELICENSING
"Massive Multiauthor Collaboration Site" (or "MMC Site") means any
World Wide Web server that publishes copyrightable works and also
provides prominent facilities for anybody to edit those works. A
public wiki that anybody can edit is an example of such a server. A
"Massive Multiauthor Collaboration" (or "MMC") contained in the site
means any set of copyrightable works thus published on the MMC site.
"CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0
license published by Creative Commons Corporation, a not-for-profit
corporation with a principal place of business in San Francisco,
California, as well as future copyleft versions of that license
published by that same organization.
"Incorporate" means to publish or republish a Document, in whole or in
part, as part of another Document.
An MMC is "eligible for relicensing" if it is licensed under this
License, and if all works that were first published under this License
somewhere other than this MMC, and subsequently incorporated in whole
or in part into the MMC, (1) had no cover texts or invariant sections,
and (2) were thus incorporated prior to November 1, 2008.
The operator of an MMC Site may republish an MMC contained in the site
under CC-BY-SA on the same site at any time before August 1, 2009,
provided the MMC is eligible for relicensing.
223
Index
Symbols
/etc/apache2, 10
/etc/group, 32
/etc/httpd, 10
/etc/inetd.conf, 127
/etc/init.d/samba, 116
/etc/init.d/smb, 116
/etc/init.d/winbind, 117
/etc/named.conf, 60
/etc/nsswitch.conf, 165, 167
/etc/passwd, 32, 174
/etc/resolv.conf, 48
/etc/samba/passdb.tdb, 173
/etc/samba/smb.conf, 121, 122, 123, 139, 163
/etc/samba/smbpasswd, 144, 171
/etc/selinux/config, 187
/etc/squid/squid.conf, 24
/etc/sysctl.conf, 91
/etc/xinetd.d/swat, 127
/proc/sys/net/ipv4/ip_forward, 91
/selinux, 189
/selinux/enforce, 189
/var/log/audit/audit.log, 185
/var/log/squid, 25
.htaccess, 22
.htpasswd, 20
.my.cnf, 33
A
A (DNS record), 53
AAAA (DNS record), 53
allow hosts (Samba), 156
apache2, 6
aptitude, 113, 114
aptitude(8), 31
auditd, 185
authoritative (dns), 56
authoritative zone, 52
axfr, 58
B
bind(DNS), 71
browsable (Samba), 157
browseable (Samba), 157
browser master, 171
C
cahing only name server, 54
chain (iptables), 98
char(mysql), 36
chcon(1), 191, 192
chkconfig, 185
chmod, 188
CIFS, 118
CNAME (DNS record), 53
context type(selinux), 190
create(mysql), 34, 36, 42
create mask (Samba), 157
D
delete(mysql), 41
deny hosts (Samba), 157
describe(mysql), 37
dhclient, 93
dhcp server, 48
directory mask (Samba), 157
directory security mask(samba), 158
DNAT, 90
dns, 47, 47
dns namespace, 49
dns server, 48
domain (dns), 50
domainname, 52
domain name system, 47, 47
dpkg, 113
dpkg(1), 31
drop(mysql), 35, 37, 43
F
filter table (iptables), 98
firewall, 89
force create mode(samba), 158
force directory mode(samba), 158
force directory security mode(samba), 158
force group(samba), 145
force security mode(samba), 158
force user(samba), 145
forwarder (dns), 54
forward lookup query, 48
fqdn, 52
fully qualified domain name, 52
G
getenforce, 186
getent(1), 166
getfattr(1), 192
glue record (dns), 53
grant(mysql), 35
group by(mysql), 41
guest ok (Samba), 132
H
hide unreadable (Samba), 157
host (DNS record), 53
hostname, 52, 118
hosts.txt, 47
hosts allow (Samba), 156
hosts deny (Samba), 157
htpasswd(1), 20
httpd, 7
224
Index
I
IBM, 118
id(1), 191
identity(selinux), 189
idmap gid(samba), 163
idmap uid(samba), 163
inetd(8), 127
insert(mysql), 38
integer(mysql), 36
invalid users (Samba), 156
iptables, 97, 98
iptables save, 102
iterative query, 55
ixfr, 58
L
LAMP, 30
ls, 188
ls(1), 192
M
mac address, 92
mangle table (iptables), 98
masquerading, 90
master server (DNS), 57
MX (DNS record), 53
mysql, 30, 32, 33, 34
mysql(group), 32
mysql(user), 32
mysql-client, 31
mysqld, 32
mysql-server, 31
N
NAPT, 90
NAT, 90
nat table (iptables), 98
NetBIOS names, 118
netcat, 135
net groupmap, 176
net rpc join(samba), 164
net use(microsoft), 134, 139, 150
net view(microsoft), 121, 126
nmbd(8), 117
NS (DNS record), 53
nslookup, 48
NT_STATUS_BAD_NETWORK_NAME, 151
NT_STATUS_LOGON_FAILURE, 151
O
order by(mysql), 40
P
packet filtering, 89, 99
packet forwarding, 89
passdb backend (Samba), 145
PAT, 90
Paul Mockapetris, 47
php, 30
ping, 92, 93
port forwarding, 90
primary dns server, 56
primary server (DNS), 57
proxy server, 24
ps(1), 192
PTR (DNS record), 53
Q
query (dns), 48
R
read list (Samba), 156
read only (Samba), 139
recursive query, 55
reverse lookup query, 48
roaming profiles(samba), 175
role(selinux), 189
root(DNS), 49
root(mysql), 31
root hints, 50
root server (dns), 55
root servers (dns), 49
router, 89
rpm, 113
rpm(1), 31
rpm(8), 114
S
samba, 113
secondary dns server, 56
secondary server (DNS), 57
security(Samba), 132
security mask(samba), 158
security mode(samba), 149
select(mysql), 38, 39, 39
SELinux, 184
selinux, 187
selinux-activate, 185
service(8), 116
sestatus, 187
setenforce, 186
show(mysql), 34, 36
slave server (DNS), 57
SMB, 118
smbclient, 124, 133
smbclient(1), 123, 150
smbd(8), 117, 121, 144
smbpasswd(1), 176
smbpasswd(8), 144, 149
smbtree, 126
smbtree(1), 125
smtp, 53
SNAT, 90
225
Index
T
tcpdump, 93
tdbsam, 145, 171, 173
testparm(1), 122, 122, 123
tld, 51
TLD (dns), 51
top level domain, 51
transition(selinux), 191
trigger(mysql), 42
triggers(mysql), 31
type(selinux), 190
U
update(mysql), 39
use(mysql), 35
V
valid users (Samba), 156
varchar(mysql), 36
virtualbox, 92
vmware, 92
W
wbinfo(1), 165, 166
webalizer, 22
winbind(8), 165
winbind(samba), 163
winbindd(8), 117, 117, 165
wireshark, 93
workgroup, 132
writable (Samba), 139
write list (Samba), 156
X
xinetd(8), 127
Y
yum, 114
Z
zone (dns), 52, 56
zone transfer (dns), 56
226