Skip to content

Commit

Permalink
Replace ifconfig/route command with ip command
Browse files Browse the repository at this point in the history
  • Loading branch information
otahi committed Jun 4, 2016
1 parent a023b56 commit f896964
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/phut/netns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ def setup_netns
def setup_link
setup_vlan
setup_mac_address
sh "sudo ip netns exec #{name} ip link set lo up"
sh "sudo ip netns exec #{name}"\
" ip link set #{network_device}#{vlan_suffix} up"
end

def setup_vlan
return unless vlan
sh "sudo ip netns exec #{name}"\
" ifconfig #{network_device} up"
" ip link set #{network_device} up"
sh "sudo ip netns exec #{name}"\
" ip link add link #{network_device} name"\
" #{network_device}#{vlan_suffix} type vlan id #{vlan}"
Expand All @@ -63,11 +66,11 @@ def setup_mac_address
end

def setup_ip
sh "sudo ip netns exec #{name} ifconfig lo 127.0.0.1"
sh "sudo ip netns exec #{name} ip addr replace 127.0.0.1 dev lo"
sh "sudo ip netns exec #{name}"\
" ifconfig #{network_device}#{vlan_suffix} #{ip} netmask #{netmask}"
" ip addr replace #{ip}/#{netmask} dev #{network_device}#{vlan_suffix}"
sh "sudo ip netns exec #{name}"\
" route add -net #{net} gw #{gateway}" if gateway
" ip route add #{net} via #{gateway}" if gateway
end

def vlan_suffix
Expand Down

0 comments on commit f896964

Please sign in to comment.