Skip to content

Instantly share code, notes, and snippets.

@aripalo
Forked from renier/fix_vbox_net.rb
Last active February 10, 2016 16:30
Show Gist options
  • Save aripalo/dbe30deed36e63e5a8a1 to your computer and use it in GitHub Desktop.
Save aripalo/dbe30deed36e63e5a8a1 to your computer and use it in GitHub Desktop.
Add exception to ipfw firewall (fixes Vagrant+VirtualBox with Cisco VPN)

Should work for Vagrant managed VirtualBox virtual machines hosted on OS X (up to OS X Maverics which has ipfw-based firewall. OS X Yosemite has another pf-based firewall so not sure about that...)

Usage:

Run with sudo and pass in your VirtualBox managed VM's vboxnet IP address or address range:

sudo ruby add_ipfw_exception.rb 172.16.0.0/12
#!ruby
if ENV['USER'] != 'root'
puts "I need to run with sudo!"
exit(1)
end
if ARGV[0].nil?
puts "Please provide the ip address or ip range for the exception"
exit(0)
end
deny_rule_string = 'deny ip from any to any'
deny_rule_id = nil
rules = `ipfw list`.split(/\n/)
rules.each do |rule|
if rule.index(deny_rule_string)
deny_rule_id = rule.split(/ /).first
break
end
end
if deny_rule_id.nil?
puts "Bad rule was not found. Carry on."
exit(0)
end
`ipfw add #{deny_rule_id.to_i - 1} allow ip from #{ARGV[0]} to any`
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment