Bert Van Vreckem
LOADays, 2018-04-20
vagrant up
whoami
Interrupt me if you have remarks/questions!
Two VirtualBox VMs, set up with Vagrant
Host | IP | Service |
---|---|---|
web |
192.168.56.72 | http, https (Apache) |
db |
192.168.56.73 | mysql (MariaDB) |
web
, a PHP app runs a query on the db
db
is set up correctly, web
is not$ git clone https://github.com/bertvv/presentation-network-troubleshooting.git
[...]
$ cd presentation-network-troubleshooting/
$ vagrant status
Current machine states:
db not created (virtualbox)
web not created (virtualbox)
This environment represents multiple VMs. The VMs are all listed
above with their current state. For more information about a specific
VM, run `vagrant status NAME`.
$ vagrant up
[...]
$ ./query_db.sh
+ mysql --host=192.168.56.73 --user=demo_user \
+ --password=ArfovWap_OwkUfeaf4 demo \
+ '--execute=SELECT * FROM demo_tbl;'
+----+-------------------+
| id | name |
+----+-------------------+
| 1 | Tuxedo T. Penguin |
| 2 | Bobby Tables |
+----+-------------------+
+ set +x
TCP/IP protocol stack
Layer | Protocols | Keywords |
---|---|---|
Application | HTTP, DNS, SMB, FTP, ... | |
Transport | TCP, UDP | sockets, port numbers |
Internet | IP, ICMP | routing, IP address |
Network access | Ethernet | switch, MAC address |
Physical | cables |
ip link
Best of both worlds!
Know the expected values!
Host | IP |
---|---|
VM | 10.0.2.15/24 |
Gateway | 10.0.2.2 |
DNS | 10.0.2.3 |
The "default" host-only network:
IP | |
---|---|
Host system | 192.168.56.1/24 |
Virtual DHCP | 192.168.56.100 |
Range from | 192.168.56.101 |
Range to | 192.168.56.254 |
Checking Local network configuration:
ip a
ip r
/etc/resolv.conf
ip address
/etc/sysconfig/network-scripts/ifcfg-*
Example: DHCP
[vagrant@db ~]$ cat /etc/sysconfig/network-scripts/ifcfg-enp0s3
TYPE=Ethernet
BOOTPROTO=dhcp
NAME=enp0s3
DEVICE=enp0s3
ONBOOT=yes
[...]
Example: Static IP
$ cat /etc/sysconfig/network-scripts/ifcfg-enp0s8
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.56.73
NETMASK=255.255.255.0
DEVICE=enp0s8
[...]
Watch the logs: sudo journalctl -f
ip route
/etc/resolv.conf
nameserver
option present?Checking routing within the LAN:
dig
, nslookup
, getent
)ping
ping 192.168.56.72
ping 192.168.56.1
ping 10.0.2.2
ping 10.0.2.3
Remark: some routers block ICMP!
dig icanhazip.com
nslookup icanhazip.com
getent ahosts icanhazip.com
Next step: routing beyond GW
sudo systemctl status SERVICE
sudo ss -tulpn
sudo firewall-cmd --list-all
systemctl status httpd.service
active (running)
vs. inactive (dead)
systemctl start httpd
enabled
vs. disabled
systemctl enable httpd
ss
(not netstat
)
sudo ss -tlnp
sudo ss -ulnp
/etc/services
sudo firewall-cmd --list-all
--add-service
if possible
--get-services
--add-service
and --add-port
--permanent
--reload
firewall rules$ sudo firewall-cmd --add-service=http --permanent
$ sudo firewall-cmd --add-service=https --permanent
$ sudo firewall-cmd --reload
journalctl
curl
, smbclient
(Samba), dig
(DNS), etc.journalctl
: journalctl -f -u httpd.service
/var/log/
:
tail -f /var/log/httpd/error_log
apachectl configtest
getsebool
, setsebool
ls -Z
, chcon
, restorecon
sepolicy
ls -Z /var/www/html
sudo restorecon -R /var/www/
sudo chcon -t httpd_sys_content_t test.php
getsebool -a | grep http
sudo setsebool -P httpd_can_network_connect_db on
Let's try to set DocumentRoot "/vagrant/www"
$ sudo vi /etc/httpd/conf/httpd.conf
$ ls -Z /vagrant/www/
-rw-rw-r--. vagrant vagrant system_u:object_r:vmblock_t:s0 test.php
$ sudo chcon -R -t httpd_sys_content_t /vagrant/www/
chcon: failed to change context of ‘test.php’ to ‘system_u:object_r:httpd_sys_content_t:s0’: Operation not supported
chcon: failed to change context of ‘/vagrant/www/’ to ‘system_u:object_r:httpd_sys_content_t:s0’: Operation not supported
Instead of setting the files to the expected context, allow httpd to access files with vmblock_t
context
Allow Apache to run in "permissive" mode:
$ sudo semanage permissive -a httpd_t
Generate "Type Enforcement" file (.te)
$ sudo audit2allow -a -m httpd-vboxsf > httpd-vboxsf.te
If necessary, edit the policy
$ sudo vi httpd-vboxsf.te
Convert to policy module (.pp)
$ checkmodule -M -m -o httpd-vboxsf.mod httpd-vboxsf.te
$ semodule_package -o httpd-vboxsf.pp -m httpd-vboxsf.mod
Install module
$ sudo semodule -i httpd-vboxsf.pp
Remove permissive domain exception
$ sudo semanage permissive -d httpd_t
Tip: automate this!
Authoritative name server for domain example.com
Host | IP |
---|---|
ns1 | 192.168.56.10 |
ns2 | 192.168.56.11 |
dc | 192.168.56.40 |
web | 192.168.56.72 |
db | 192.168.56.73 |
priv0001 | 172.16.0.10 |
priv0002 | 172.16.0.11 |
$ ./tests/runtests.sh
Testing 192.168.56.10
✓ The dig command should be installed
✓ It should return the NS record(s)
✓ It should be able to resolve host names
✓ It should be able to do reverse lookups
✓ It should be able to resolve aliases
✓ It should return the SRV record(s)
6 tests, 0 failures
Testing 192.168.56.11
✓ The dig command should be installed
✓ It should return the NS record(s)
✓ It should be able to resolve host names
✓ It should be able to do reverse lookups
✓ It should be able to resolve aliases
✓ It should return the SRV record(s)
6 tests, 0 failures
journalctl -u named
named-checkconf /etc/named.conf
named-checkzone ZONE FILE
E.g. https://github.com/HoGentTIN/elnx-sme/blob/master/test/pu004/lamp.bats
How did I do? Tell me!