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/04 00:22]
kurihara
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>
 +
 +
 +\\
 +==== Fabric one-line Task Examples ====
  
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
Line 18: 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 -i "mode|currently|status|count"  /proc/net/bonding/bond*+$ fab -H $H  -- egrep  "*"  /proc/net/bonding/bond* 
 +$ fab -H $H  -- egrep -i "mode|currently|status|count"  /proc/net/bonding/bond* 
 + 
 +# Bonding Driver 
 +$ fab -H $H  -- "lsmod |grep bonding" 
 + 
 +# NIC Driver 
 +$ 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 51: 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 60: Line 73:
     run("test -d /tmp/nwconf_%s || mkdir /tmp/nwconf_%s" % date)     run("test -d /tmp/nwconf_%s || mkdir /tmp/nwconf_%s" % date)
     # RHEL/CentOS     # RHEL/CentOS
-    run("/usr/bin/cp -f /etc/sysconfig/network-scripts/ifcfg* /tmp/nwconf_%s/" % date)+    run("cp -f /etc/sysconfig/network-scripts/ifcfg* /tmp/nwconf_%s/" % date)
     # Debian/Ubuntu     # Debian/Ubuntu
-    run("/usr/bin/cp -f /etc/network/interfaces /tmp/nwconf_%s/" % date) +    run("cp -f /etc/network/interfaces /tmp/nwconf_%s/" % date) 
-    run("/usr/bin/cp -f /etc/sysconfig/static-routes /tmp/nwconf_%s/" % date)+    run("cp -f /etc/sysconfig/static-routes /tmp/nwconf_%s/" % date)
  
  
Line 70: 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", "/etc/sysconfig/network-scripts/ifcfg-%s", use_sudo=True % (FHHOMEbond)) +    put("%s/etc/sysconfig/network-scripts/ifcfg-bond.tpl" % FHHOME, "/tmp/ifcfg-%s.%s" % (bond,date)) 
-    put("%s/etc/sysconfig/network-scripts/ifcfg-bond_nic.tpl", "/etc/sysconfig/network-scripts/ifcfg-%s", use_sudo=True % (FHHOME, nic1)) +    put("%s/etc/sysconfig/network-scripts/ifcfg-bond_nic.tpl" % FHHOME, "/tmp/ifcfg-%s.%s" % (nic1,date)) 
-    put("%s/etc/sysconfig/network-scripts/ifcfg-bond_nic.tpl", "/etc/sysconfig/network-scripts/ifcfg-%s", use_sudo=True % (FHHOME, nic2))+    put("%s/etc/sysconfig/network-scripts/ifcfg-bond_nic.tpl" % FHHOME, "/tmp/ifcfg-%s.%s" % (nic2,date)) 
     # bond     # bond
-    sed("/etc/sysconfig/network-scripts/ifcfg-%s", before="DEVICE=bondX", after="DEVICE=%s ,use_sudo=True" % (bond, ip)+    sed("/tmp/ifcfg-%s.%s" % (bond,date), before="DEVICE=bondX", after="DEVICE=%s" % ip) 
-    sed("/etc/sysconfig/network-scripts/ifcfg-%s", before="IPADDR=x.x.x.x", after="IPADDR=%s ,use_sudo=True" % (bond, ip))+    sed("/tmp/ifcfg-%s.%s" % (bond,date), before="IPADDR=x.x.x.x", after="IPADDR=%s" % ip)
     # nic1     # nic1
-    sed("/etc/sysconfig/network-scripts/ifcfg-%s", before="DEVICE=X", after="DEVICE=%s ,use_sudo=True" % (nic1, nic1)+    sed("/tmp/ifcfg-%s.%s" % (nic1,date), before="DEVICE=X", after="DEVICE=%s" % nic1) 
-    sed("/etc/sysconfig/network-scripts/ifcfg-%s", before="MASTER=X", after="MASTER=%s ,use_sudo=True" % (nic1, bond))+    sed("/tmp/ifcfg-%s.%s" % (nic1,date), before="MASTER=X", after="MASTER=%s" % bond)
     # nic2     # nic2
-    sed("/etc/sysconfig/network-scripts/ifcfg-%s", before="DEVICE=X", after="DEVICE=%s ,use_sudo=True" % (nic2, nic2)) +    sed("/tmp/ifcfg-%s.%s" % (nic2,date), before="DEVICE=X", after="DEVICE=%s" % nic2) 
-    sed("/etc/sysconfig/network-scripts/ifcfg-%s", before="MASTER=X", after="MASTER=%s ,use_sudo=True" % (nic2, bond))+    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" % (nic1,date,nic1)) 
 +    run("diff /tmp/ifcfg-%s.%s  /etc/sysconfig/network-scripts/ifcfg-%s" % (nic2,date,nic2)) 
 + 
 +    sudo("mv /tmp/ifcfg-%s.%s  /etc/sysconfig/network-scripts/ifcfg-%s" % (bond,date,bond)) 
 +    sudo("mv /tmp/ifcfg-%s.%s /etc/sysconfig/network-scripts/ifcfg-%s% (nic1,date.nic1)) 
 +    sudo("mv /tmp/ifcfg-%s.%s /etc/sysconfig/network-scripts/ifcfg-%s" % (nic2,date,nic2)) 
 + 
 </sxh> </sxh>
  
Line 90: Line 115:
 \\ \\
 ===== Configuration ===== ===== Configuration =====
 +  *ifcfg-bond.tpl 
 +  *ifcfg-bond_nic.tpl
  
 \\ \\


os/linux/net/index.html.1514992958.txt.gz · Last modified: 2018/01/04 00:22 by kurihara