FastHandle - IT Operations Examples

FastHandle is fast operation tools for infrastructure configurations and tests.

User Tools

Site Tools


os:linux:net:index.html



Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
os:linux:net:index.html [2018/01/10 01:27]
kurihara [net.py]
os:linux:net:index.html [2019/02/11 00:40] (current)
kurihara
Line 1: Line 1:
 [[:index.html#OS Management|Top#OS Management]] [[:index.html#OS Management|Top#OS Management]]
-====== Network Configuration (net.py) ======+====== Linux Network Configuration with Fabric (net.py) ======
  
 $FHHOME/fabfile/net.py $FHHOME/fabfile/net.py
Line 8: Line 8:
  
  
-===== Operation =====+===== Operation with Fabric =====
  
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ fab -l |grep net+$ fab -l |grep -F net.
 </sxh> </sxh>
  
  
-==== Remote Shell Commands ====+\\ 
 +==== Fabric one-line Task Examples ====
  
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
Line 21: Line 22:
  
 # Interface's IP # Interface's IP
-$ fab -H $H auth.pro -- "ip a |grep inet"+$ fab -H $H  -- "ip a |grep inet"
  
 # Bonding # Bonding
-$ fab -H $H auth.pro -- egrep  "*"  /proc/net/bonding/bond* +$ fab -H $H  -- egrep  "*"  /proc/net/bonding/bond* 
-$ fab -H $H auth.pro -- egrep -i "mode|currently|status|count"  /proc/net/bonding/bond*+$ fab -H $H  -- egrep -i "mode|currently|status|count"  /proc/net/bonding/bond*
  
 # Bonding Driver # Bonding Driver
-$ fab -H $H auth.pro -- "lsmod |grep bonding"+$ fab -H $H  -- "lsmod |grep bonding"
  
 # NIC Driver # NIC Driver
-$ fab -H $H auth.pro -- for i in `ip a |grep mtu |awk -F: {'print $2'} |egrep -v "lo"` ; do echo "----------" ; echo $i ;echo "----------"; ethtool -i $i ; done+$ fab -H $H  -- for i in `ip a |grep mtu |awk -F: {'print $2'} |egrep -v "lo"` ; do echo "----------" ; echo $i ;echo "----------"; ethtool -i $i ; done
  
  
 # Routing # Routing
-$ fab -H $H auth.pro -- netstat -rn +$ fab -H $H  -- netstat -rn 
-$ fab -H $H auth.pro -- cat /etc/sysconfig/static-route+$ fab -H $H  -- cat /etc/sysconfig/static-route
  
 # nmap # nmap
-$ fab -H $H auth.pro -- sudo nmap -Pn -sT -p 22 xx.xx.xx.xx+$ fab -H $H  -- sudo nmap -Pn -sT -p 22 xx.xx.xx.xx
  
 # tcpdump # tcpdump
-$ fab -H $H auth.pro -- sudo tcpdump  udp port 53 -i any  -W1 -G60 +$ fab -H $H  -- sudo tcpdump  udp port 53 -i any  -W1 -G30  # check 30 seconds 
-$ fab -H $H auth.pro -- sudo tcpdump -n not arp and not port 123 and not port 22  -W1 -G60+$ fab -H $H  -- sudo tcpdump -n not arp and not port 123 and not port 22  -W1 -G30  # check 30 seconds
  
 # DNS # DNS
-$ fab -H $H auth.pro -- cat /etc/resolv.conf +$ fab -H $H  -- cat /etc/resolv.conf 
-$ fab -H $H auth.pro -- host google.com +$ fab -H $H  -- host google.com 
-$ fab -H $H auth.pro -- host test-server-01 +$ fab -H $H  -- host test-server-01 
-$ fab -H $H auth.pro -- host x.x.x.x+$ fab -H $H  -- host x.x.x.x
 </sxh> </sxh>
  
Line 62: Line 63:
 from fabric.api import * from fabric.api import *
 from fabric.contrib import files from fabric.contrib import files
 +from datetime import datetime
  
 FHHOME=os.environ["FHHOME"] FHHOME=os.environ["FHHOME"]
Line 81: Line 83:
 def set_bond(ip,bond,nic1,nic2): def set_bond(ip,bond,nic1,nic2):
     backup_config()     backup_config()
 +    date = datetime.now().strftime('%Y%m%d_%H%M')
     # put     # put
     put("%s/etc/sysconfig/network-scripts/ifcfg-bond.tpl" % FHHOME, "/tmp/ifcfg-%s.%s" % (bond,date))     put("%s/etc/sysconfig/network-scripts/ifcfg-bond.tpl" % FHHOME, "/tmp/ifcfg-%s.%s" % (bond,date))
Line 87: Line 90:
  
     # bond     # bond
-    sed("/tmp/ifcfg-%s.%s" % (bond,date), before="DEVICE=bondX", after="DEVICE=%s" % ip ,use_sudo=True+    sed("/tmp/ifcfg-%s.%s" % (bond,date), before="DEVICE=bondX", after="DEVICE=%s" % ip) 
-    sed("/tmp/ifcfg-%s.%s" % (bond,date), before="IPADDR=x.x.x.x", after="IPADDR=%s" % ip ,use_sudo=True)+    sed("/tmp/ifcfg-%s.%s" % (bond,date), before="IPADDR=x.x.x.x", after="IPADDR=%s" % ip)
     # nic1     # nic1
-    sed("/tmp/ifcfg-%s.%s" % (nic1,date), before="DEVICE=X", after="DEVICE=%s" % nic1 ,use_sudo=True+    sed("/tmp/ifcfg-%s.%s" % (nic1,date), before="DEVICE=X", after="DEVICE=%s" % nic1) 
-    sed("/tmp/ifcfg-%s.%s" % (nic1,date), before="MASTER=X", after="MASTER=%s" % bond ,use_sudo=True)+    sed("/tmp/ifcfg-%s.%s" % (nic1,date), before="MASTER=X", after="MASTER=%s" % bond)
     # nic2     # nic2
-    sed("/tmp/ifcfg-%s.%s" % (nic2,date), before="DEVICE=X", after="DEVICE=%s" % nic2 ,use_sudo=True+    sed("/tmp/ifcfg-%s.%s" % (nic2,date), before="DEVICE=X", after="DEVICE=%s" % nic2) 
-    sed("/tmp/ifcfg-%s.%s" % (nic2,date), before="MASTER=X", after="MASTER=%s" % bond ,use_sudo=True)+    sed("/tmp/ifcfg-%s.%s" % (nic2,date), before="MASTER=X", after="MASTER=%s" % bond)
  
     run("diff /tmp/ifcfg-%s.%s  /etc/sysconfig/network-scripts/ifcfg-%s" % (bond,date,bond))     run("diff /tmp/ifcfg-%s.%s  /etc/sysconfig/network-scripts/ifcfg-%s" % (bond,date,bond))


os/linux/net/index.html.1515515241.txt.gz · Last modified: 2018/01/10 01:27 by kurihara