Skip to content

Instantly share code, notes, and snippets.

@zigarn
Last active July 29, 2018 08:23
Show Gist options
  • Save zigarn/d914ea47b0e09b327fd8c24d315f5894 to your computer and use it in GitHub Desktop.
Save zigarn/d914ea47b0e09b327fd8c24d315f5894 to your computer and use it in GitHub Desktop.
Vagrantfile mDNS
# -*- mode: ruby -*-
# vi: set ft=ruby expandtab shiftwidth=2 :
# Add time logging
def $stdout.write string
log_datas=string
if log_datas.gsub(/\r?\n/, '') != ''
log_datas=::Time.now.strftime('%FT%T%z')+' '+log_datas.gsub(/\r\n/, '\n')
end
super log_datas
end
def $stderr.write string
log_datas=string
if log_datas.gsub(/\r?\n/, '') != ''
log_datas=::Time.now.strftime('%d/%m/%Y %T')+' '+log_datas.gsub(/\r\n/, '\n')
end
super log_datas
end
domainname = "mydomain.local"
hosts = [
'NAME',
]
Vagrant.configure(2) do |config|
config.vm.box = "centos/7"
hosts.each do |name|
config.vm.define name do |host|
host.vm.hostname = "#{name}.#{domainname}"
end
end
config.vm.network "private_network", type: "dhcp"
# Fool Ansible to use eth1 interface as default IP
config.vm.provision "shell",
:inline => "echo '8.8.8.8 dev eth1' > /etc/sysconfig/network-scripts/route-eth1
echo '2404:6800:400a:800::1012 dev eth1' > /etc/sysconfig/network-scripts/route6-eth1"
# Always reload routes (looks like ipv6 routes are not reloaded on reboot)
config.vm.provision "shell",
:run => "always",
:inline => "{ /etc/sysconfig/network-scripts/ifup-routes eth1 || true; } >/dev/null 2>&1"
# Install & configure avahi/mdns
config.vm.provision "shell",
:inline => "domainname $(hostname --domain)
yum install --assumeyes --quiet epel-release
yum install --assumeyes --quiet avahi nss-mdns
sed -i \"s/#host-name=.*/host-name=$(hostname --short)/;s/#domain-name=.*/domain-name=$(hostname --domain)/\" /etc/avahi/avahi-daemon.conf
IPTABLE_REJECT_INDEX=$(/sbin/iptables -L INPUT --line-numbers | awk '/REJECT/{print $1}')
/sbin/iptables -I INPUT ${IPTABLE_REJECT_INDEX:-1} -p tcp -m state -m tcp --dport 548 --state NEW -j ACCEPT
/sbin/iptables -I INPUT ${IPTABLE_REJECT_INDEX:-1} -p udp -m state -m udp --dport 548 --state NEW -j ACCEPT
/sbin/iptables -I INPUT ${IPTABLE_REJECT_INDEX:-1} -p tcp -m state -m tcp --dport 5353 --state NEW -j ACCEPT
/sbin/iptables -I INPUT ${IPTABLE_REJECT_INDEX:-1} -p udp -m state -m udp --dport 5353 --state NEW -j ACCEPT
/sbin/iptables -I INPUT ${IPTABLE_REJECT_INDEX:-1} -p tcp -m state -m tcp --dport 5354 --state NEW -j ACCEPT
/sbin/iptables -I INPUT ${IPTABLE_REJECT_INDEX:-1} -p udp -m state -m udp --dport 5354 --state NEW -j ACCEPT
/sbin/service iptables save
/sbin/service avahi-daemon restart"
# Open required port for mDNS (https://bugzilla.redhat.com/show_bug.cgi?id=704809#c7)
config.vm.provision "shell",
:inline => "IPTABLE_REJECT_INDEX=$(/sbin/iptables -L INPUT --line-numbers | awk '/REJECT/{print $1}')
/sbin/iptables -I INPUT ${IPTABLE_REJECT_INDEX:-1} -p tcp -m state -m tcp --dport 548 --state NEW -j ACCEPT
/sbin/iptables -I INPUT ${IPTABLE_REJECT_INDEX:-1} -p udp -m state -m udp --dport 548 --state NEW -j ACCEPT
/sbin/iptables -I INPUT ${IPTABLE_REJECT_INDEX:-1} -p tcp -m state -m tcp --dport 5353 --state NEW -j ACCEPT
/sbin/iptables -I INPUT ${IPTABLE_REJECT_INDEX:-1} -p udp -m state -m udp --dport 5353 --state NEW -j ACCEPT
/sbin/iptables -I INPUT ${IPTABLE_REJECT_INDEX:-1} -p tcp -m state -m tcp --dport 5354 --state NEW -j ACCEPT
/sbin/iptables -I INPUT ${IPTABLE_REJECT_INDEX:-1} -p udp -m state -m udp --dport 5354 --state NEW -j ACCEPT
/sbin/service iptables save"
config.ssh.insert_key = false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment