Für ein reines „pgk“ Setup ohne Ports ohne zusätzlichen User.
vi /etc/motd
pkg update pkg install zsh vim-lite git wget curl nullmailer ezjail atop py27-powerline-status powerline-fonts most
Setup für zsh, vim, git usw.
cd git clone https://github.com/mahescho/dotfiles.git cd ~/dotfiles ./initdf.sh
Mir reicht der „Nullmailer“, ich mag „atop“, Syslog Setup damit in den Jails auch Syslog funktioniert und den Inetd, da ich check_mk benutze:
vi /etc/rc.conf
Hinzufügen:
sendmail_enable="NO" sendmail_submit_enable="NO" sendmail_outbound_enable="NO" sendmail_msp_queue_enable="NO" nullmailer_enable="YES" atop_enable="YES" syslogd_flags="-ss -a 127.0.0.1 -C" inetd_enable=yes inetd_flags=-wW
Nullmailerconfig in „/usr/local/etc/nullmailer“ anpassen.
Wenn keine weiteren öffentliche IPv4 IPs zur Verfügung stehen wird ein lokales RFC 1918 Netz und NAT für die Jails benötigt:
vi /etc/rc.conf
Hinzufügen nach Bedarf z.B:
cloned_interfaces="lo0" ifconfig_lo0_alias0="inet 10.0.0.1 netmask 255.255.255.0" ifconfig_lo0_alias1="inet 10.0.0.2 netmask 255.255.255.0"
Wenn öffentliche IPv4 IPs vorhanden sind, einfach Interface-Aliase hinzufügen:
ifconfig_vtnet0_alias0="inet 8.7.6.5 netmask 0xffffff00" ifconfig_vtnet0_alias1="inet 9.8.7.6 netmask 0xffffff00"
einfach „fe80::“ als defaultgateway zu nehmen hat sich nich bewährt. Bei manchen hostern funktioniert das nich zuverlässig. Zuverlässig funktioniert aber „link-local“ zu verwenden. Zu ermitteln mittels:
ping -c 1 ff02::2%vtnet0
ergebnis: fe80::xxxx:xxxx:xxxx:xxxx%vtnet0
vi /etc/rc.conf
Hinzufügen:
# IPv6 ipv6_activate_all_interfaces="YES" ipv6_network_interfaces="vtnet0" ifconfig_vtnet0_ipv6="inet6 xxxx:xxxx:xxxx:xxxx::xxxx prefixlen 64" ipv6_defaultrouter="fe80::xxxx:xxxx:xxxx:xxxx%vtnet0" ipv6_gateway_enable="YES"
Wenn in den Jails weitere IPv6 IPs benötigt werden auch hier einfach Aliase hinzufügen:
ifconfig_vtnet0_ipv6_alias0="inet6 xxxx:xxxx:xxxx:xxxx::xxxx prefixlen 64" ifconfig_vtnet0_ipv6_alias1="inet6 xxxx:xxxx:xxxx:xxxx::xxxx prefixlen 64"
Beim Booten aktivieren:
vi /etc/rc.conf
Hinzufügen:
pf_enable="YES" pf_rules="/etc/pf.conf" pflog_enable="YES" pflog_logfile="/var/log/pflog"
Logverzeichnis anlegen:
mkdir /var/log/pflog
Meine Config:
„re0“ muss wie auch die IPs angepasst werden
if = "{ re0 }"
table <rfc1918> persist { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 224.0.0.0/5 }
table <MHC> { 1.2.3.4/29 }
table <MHC6> { xxx:xxx:xxx:xxx::/48}
icmp_types = "echoreq"
open_tcp = "{ 80, 443 }"
open_udp = "{ 80 }"
check_mk = "{ 6556 }"
jails = "{ 10.0.0.1, 10.0.0.2}"
jails_net ="10.0.0.0/24"
ip = 4.5.6.7 # IP des Hosts
www = 10.0.0.2
m01 = 2.3.4.5 # IP des Nagiosservers
set block-policy drop
set skip on lo0
set timeout { interval 10, frag 30 }
set timeout { tcp.first 120, tcp.opening 30, tcp.established 86400 }
set timeout { tcp.closing 900, tcp.finwait 45, tcp.closed 90 }
set timeout { udp.first 60, udp.single 30, udp.multiple 60 }
set timeout { icmp.first 20, icmp.error 10 }
set timeout { other.first 60, other.single 30, other.multiple 60 }
set timeout { adaptive.start 0, adaptive.end 0 }
set limit { states 10000, frags 5000 }
set loginterface re0
set optimization normal
set require-order yes
set fingerprints "/etc/pf.os"
set ruleset-optimization basic
scrub in all fragment reassemble random-id
rdr on $if proto tcp from any to $if port { 80, 443 } -> $www
rdr on $if proto udp from any to $if port { 80 } -> $www
nat on $if proto {tcp udp icmp} from $jails to any -> $ip
block log all
block return
antispoof quick for $if
pass in quick proto icmp6 all
pass in quick from <MHC> to any keep state
pass in quick inet6 from <MHC6> to any keep state
pass in on $if proto tcp from any to any port $open_tcp keep state
pass in on $if proto udp from any to any port $open_udp keep state
pass in on $if proto tcp from $m01 to $ip port $check_mk keep state
pass out quick all keep state
pass in on $if inet proto icmp all icmp-type $icmp_types keep state
pass in on $if inet proto icmp all icmp-type $icmp_types keep state
pass in on $if inet proto udp from any to any port 33433 >< 33626 keep state
pass in on $if inet proto udp from any to any port 33433 >< 33626 keep state
pf starten
service pf start service pflog start
Nützliche Komandos
| Komando | Zweck |
| pfctl -e | Enable PF. |
| pfctl -d | Disable PF. |
| pfctl -F all -f /etc/pf.conf | Flush all NAT, filter, state, and table rules and reload /etc/pf.conf. |
| pfctl -s [ rules | nat | states ] | Report on the filter rules, NAT rules, or state table. |
| pfctl -vnf /etc/pf.conf | Check /etc/pf.conf for errors, but do not load ruleset. |
vi /usr/local/etc/ezjail.conf
Meine Einstellungen:
ezjail_use_zfs="YES" ezjail_use_zfs_for_jails="YES" ezjail_jailzfs="zroot/ezjail" ezjail_zfs_properties="-o atime=off"
vi /etc/rc.conf
Hinzufügen:
ezjail_enable="YES"
In den Jail-Configs, für Ping:
export jail_www_parameters="allow.raw_sockets allow.sysvipc"
Jails anlegen:
ezjail-admin create JailName IP,IP
ezjail-admin console JailName
vi /etc/motd
pkg update pkg install zsh vim-lite git nullmailer py27-powerline-status powerline-fonts most
Setup für zsh, vim, git usw.
cd git clone https://github.com/mahescho/dotfiles.git cd ~/dotfiles ./initdf.sh
vi /etc/rc.conf
Hinzufügen:
sendmail_enable="NO" sendmail_submit_enable="NO" sendmail_outbound_enable="NO" sendmail_msp_queue_enable="NO" nullmailer_enable="YES" inetd_enable=yes inetd_flags=-wW
Nullmailerconfig in „/usr/local/etc/nullmailer“ anpassen.