Advertisement
tolikpunkoff

netnamespace

Mar 8th, 2019
744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.76 KB | None | 0 0
  1. #!/bin/bash
  2. #pered nastroikoi otkluchit' NetworkManager k heram!!!
  3.  
  4. wait_to()
  5. {
  6.     L_MESS=$1
  7.     L_DEV=$2
  8.     L_ST=$3
  9.     L_TIME=$4
  10.     L_NS=$5
  11.     L_LOOP=0
  12.     L_RETCODE=666
  13.    
  14.     echo -n $L_MESS
  15.     while [ $L_LOOP -eq 0 ];do
  16.     echo -n "."
  17.     if [ -z $L_NS  ]; then
  18.         ./ndstatus $L_DEV -s
  19.         L_RETCODE=$?
  20.     else
  21.         ip netns exec $L_NS ./ndstatus $L_DEV -s
  22.         L_RETCODE=$?
  23.     fi
  24.    
  25.     if [[ "$L_ST"=="up" ]]; then
  26.         if [ $L_RETCODE -eq 0 ]; then
  27.         L_LOOP=1
  28.         echo
  29.         fi
  30.     fi
  31.         if [[ "$L_ST"=="down" ]]; then
  32.         if [ $L_RETCODE -eq 1 ]; then
  33.         L_LOOP=1
  34.         echo
  35.         fi
  36.     fi
  37.    
  38.     sleep 1
  39.     let L_TIME=L_TIME-1
  40.     if [ $L_TIME -lt 0 ]; then
  41.         echo
  42.         echo "Oops, something wrong..."
  43.         sleep 10
  44.         L_LOOP=1
  45.     fi
  46.     done
  47. }
  48.  
  49. echo "Adding  namespace..."
  50. ip netns add provns
  51.  
  52. echo "Configure virtual network card..."
  53. ip link add veth0 type veth peer name veth1
  54. ifconfig veth0 0.0.0.0 up
  55. ip link set veth1 netns provns
  56.  
  57. ifconfig eth0 down
  58. wait_to "Down network card..." eth0 down 5
  59. ifconfig eth0 0.0.0.0 up
  60. wait_to "Up network card..." eth0 up 5
  61.  
  62. echo "Configure bridge..."
  63. brctl addbr br0
  64. brctl addif br0 eth0 veth0
  65. ifconfig br0 10.10.0.119 netmask 255.255.0.0 up
  66. wait_to  "Up bridge..." br0 up 7
  67.  
  68. #echo "Delete default route..."
  69. #ip route del default
  70. echo "Add default route..."
  71. ip route add default via 10.10.0.10 dev br0 src 10.10.0.119
  72.  
  73. ip netns exec provns ifconfig veth1 10.10.0.120 netmask 255.255.0.0
  74. wait_to "Configure namespace. Up virtual network card..." veth1 up 5 provns
  75. echo "Set default route for namespace..."
  76. ip netns exec provns ip route add default via 10.10.0.10 dev veth1  src 10.10.0.120
  77. echo "Configure lo interface..."
  78. ip netns exec provns ifconfig lo 127.0.0.1
  79. echo "Network namespace configured!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement