Enterprise Linux
HOGENT applied computer science
Set up the test environment
$ cd elnx-syllabus/demo
$ vagrant up web db
[...]
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 dbdb is set up correctly, web is not$ ./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
Should work from
/vagrant/query_db.sh)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 linkKnow the expected values!
Checking Local network configuration:
ip aip r/etc/resolv.confip 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.confnameserver option present?Checking routing within the LAN:
dig, nslookup, getent)pingping 192.168.56.72ping 192.168.56.1ping 10.0.2.2ping 10.0.2.3Remark: some routers block ICMP!
dig icanhazip.comnslookup icanhazip.comgetent ahosts icanhazip.comNext step: routing beyond GW
sudo systemctl status SERVICEsudo ss -tulpnsudo firewall-cmd --list-allsystemctl status httpd.service
active (running) vs. inactive (dead)
systemctl start httpdenabled vs. disabled
systemctl enable httpdss (not netstat)
sudo ss -tlnpsudo ss -ulnp/etc/servicessudo 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
journalctlcurl, smbclient (Samba), dig (DNS), etc.ncat, nc)journalctl: journalctl -f -u httpd.service/var/log/:
tail -f /var/log/httpd/error_logapachectl configtestgetsebool, setseboolls -Z, chcon, restoreconsepolicyls -Z /var/www/htmlsudo restorecon -R /var/www/sudo chcon -t httpd_sys_content_t test.phpgetsebool -a | grep http
sudo setsebool -P httpd_can_network_connect_db onLet’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_tGenerate “Type Enforcement” file (.te)
$ sudo audit2allow -a -m httpd-vboxsf > httpd-vboxsf.teIf necessary, edit the policy
$ sudo vi httpd-vboxsf.teConvert to policy module (.pp)
$ checkmodule -M -m -o httpd-vboxsf.mod httpd-vboxsf.te
$ semodule_package -o httpd-vboxsf.pp -m httpd-vboxsf.modInstall module
$ sudo semodule -i httpd-vboxsf.ppRemove permissive domain exception
$ sudo semanage permissive -d httpd_tTip: automate this!
E.g. https://github.com/HoGentTIN/elnx-sme/blob/master/test/pu001/lamp.bats