Difference between revisions of "Network Issues"
From Blue-IT.org Wiki
(→Montitor ip changes) |
|||
Line 17: | Line 17: | ||
= Montitor ip changes = | = Montitor ip changes = | ||
+ | BIG script, inspired by some others ... | ||
+ | This script monitors a maximum of two simultanuisly connnections out of one of these | ||
+ | * ppp0 | ||
+ | * wlan0 | ||
+ | * eth0 | ||
+ | |||
+ | It reports changes on | ||
+ | * name and ip of each interface | ||
+ | * default router | ||
+ | |||
+ | It can be used to fine tune network issues. | ||
+ | |||
+ | |||
+ | #!/bin/bash | ||
+ | export LC_MESSAGES="en_US.UTF-8" | ||
+ | export LC_TYPE="en_US.UTF-8" | ||
+ | export LANGUAGE="en_US.UTF-8" | ||
+ | |||
+ | IGNORE_DEV="virbr0|tun0" | ||
+ | |||
+ | WORKING_IP="/tmp/workingip.txt" | ||
+ | GOT_IP="/tmp/gotip.txt" | ||
+ | DEV_IP="/tmp/devip.txt" | ||
+ | ADEV="/tmp/adev.txt" | ||
+ | WORKING_DEV_IP="/tmp/wdevip.txt" | ||
+ | DEV_IP2="/tmp/devip2.txt" | ||
+ | ADEV2="/tmp/adev2.txt" | ||
+ | WORKING_DEV_IP2="/tmp/wdevip2.txt" | ||
+ | DEV="/tmp/dev.txt" | ||
+ | GW_DEV="/tmp/gwdev.txt" | ||
+ | WORKING_GW_DEV="/tmp/wgwdev.txt" | ||
+ | |||
+ | # When the gateway of the system changes, do ... | ||
+ | on_gw_change() { | ||
+ | echo "gateyway changed." | ||
+ | } | ||
+ | |||
+ | # When the public internet address of the system changes, do ... | ||
+ | on_internet_adress_change() { | ||
+ | echo "public ip changed." | ||
+ | } | ||
+ | |||
+ | # When the local address of your network card(s) changes | ||
+ | on_local_address_change() { | ||
+ | echo "local ip address changed." | ||
+ | } | ||
+ | |||
+ | |||
+ | # watch -n2 "echo -n 'WRK:'; cat /tmp/workingip.txt ;echo -n 'GOT:'; cat /tmp/gotip.txt ; echo -n 'DIP:'; cat /tmp/devip.txt; echo -n 'ADEV:'; cat /tmp/adev.txt; echo -n 'WDEV:'; cat /tmp/wdevip.txt; echo -n 'GWDEV:'; cat /tmp/gwdev.txt; echo -n 'WGWDEV:'; cat /tmp/wgwdev.txt;" | ||
+ | |||
+ | # Initiate first | ||
+ | dig @ns1.google.com 2> /dev/null 1> /dev/null && myip="$(dig @ns1.google.com -t txt o-o.myaddr.l.google.com +short | sed s/\"/\/g)" | ||
+ | # myip=$(curl -s http://www.ipchicken.com/ | awk '/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/ {print $1}' | uniq | grep -v curl) | ||
+ | |||
+ | # requires stun: | ||
+ | # apt-get install stun | ||
+ | # sudo service stun stop | ||
+ | # sudo update-rc.d -f stun remove | ||
+ | #myip=$(stun -v stunserver.org 2>&1 1>/dev/null | grep MappedAddress | sed -e 's/.*MappedAddress = //' -e 's/:.*//' | uniq) | ||
+ | |||
+ | echo ${myip} > ${GOT_IP} | ||
+ | cp ${GOT_IP} ${WORKING_IP} | ||
+ | |||
+ | ACTIVE_DEVICE_1="$(nmcli dev status | grep -v disconnected | grep connected | grep -v ${IGNORE_DEV} | awk '{print $1}' | uniq | head -n1)" | ||
+ | ACTIVE_TYPE_1="$(nmcli dev status | grep -v disconnected | grep connected | awk '{print $2}' | uniq | head -n1)" | ||
+ | [ ${ACTIVE_TYPE_1} == "gsm" ] && ACTIVE_DEVICE_1="ppp0" | ||
+ | |||
+ | ACTIVE_DEVICE_2="$(nmcli dev status | grep -v disconnected | grep connected | grep -v ${IGNORE_DEV} | awk '{print $1}' | uniq | tail -n1)" | ||
+ | ACTIVE_TYPE_2="$(nmcli dev status | grep -v disconnected | grep connected | awk '{print $2}' | uniq | tail -n1)" | ||
+ | [ ${ACTIVE_TYPE_2} == "gsm" ] && ACTIVE_DEVICE_2="ppp0" | ||
+ | |||
+ | |||
+ | mygw_dev="$(route | grep default | awk '{print $8}')" | ||
+ | echo ${mygw_dev} > ${GW_DEV} | ||
+ | cp ${GW_DEV} ${WORKING_GW_DEV} | ||
+ | |||
+ | |||
+ | |||
+ | #A Actuve devices | ||
+ | if [ ${ACTIVE_TYPE_1} == "" ] | ||
+ | then | ||
+ | echo "NO ACTIVE DEVICE" | ||
+ | else | ||
+ | ACTIVE_IP_1="$(ifconfig ${ACTIVE_DEVICE_1} | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | uniq)" | ||
+ | echo ${ACTIVE_IP_1} > ${DEV_IP} | ||
+ | echo ${ACTIVE_DEVICE_1} > ${ADEV} | ||
+ | cp ${DEV_IP} ${WORKING_DEV_IP} | ||
+ | fi | ||
+ | |||
+ | # There is not second device | ||
+ | if [ "${ACTIVE_DEVICE_1}" == "${ACTIVE_DEVICE_2}" ] | ||
+ | then | ||
+ | echo "NO ACTIVE SECOND DEVICE" | ||
+ | |||
+ | echo "" > ${DEV_IP2} | ||
+ | echo "" > ${ADEV2} | ||
+ | cp ${DEV_IP} ${WORKING_DEV_IP2} | ||
+ | else | ||
+ | |||
+ | if [ ${ACTIVE_TYPE_2} == "" ] | ||
+ | then | ||
+ | echo "NO ACTIVE SECOND DEVICE" | ||
+ | else | ||
+ | ACTIVE_IP_1="$(ifconfig ${ACTIVE_DEVICE_2} | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | uniq)" | ||
+ | echo ${ACTIVE_IP_1} > ${DEV_IP2} | ||
+ | echo ${ACTIVE_DEVICE_2} > ${ADEV2} | ||
+ | cp ${DEV_IP} ${WORKING_DEV_IP2} | ||
+ | fi | ||
+ | |||
+ | fi | ||
+ | |||
+ | sleep 1 | ||
+ | |||
+ | # MAIN | ||
+ | |||
+ | while (true); do | ||
+ | |||
+ | #export LC_MESSAGES="en_US.UTF-8" | ||
+ | #export LC_TYPE="en_US.UTF-8" | ||
+ | |||
+ | # Check the gotten internet IP | ||
+ | #getip=$(curl -s http://www.ipchicken.com/ | awk '/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/ {print $1}' | uniq | grep -v curl) | ||
+ | dig @ns1.google.com 2> /dev/null 1> /dev/null && getip="$(dig @ns1.google.com -t txt o-o.myaddr.l.google.com +short | sed s/\"/\/g)" | ||
+ | echo ${getip} > ${GOT_IP} | ||
+ | |||
+ | # Check the lokal IP and interfaces | ||
+ | # Get the active device from network manager | ||
+ | ACTIVE_DEVICE_1="$(nmcli dev status | grep -v disconnected | grep connected | grep -v ${IGNORE_DEV} | awk '{print $1}' | uniq | head -n1)" | ||
+ | ACTIVE_TYPE_1="$(nmcli dev status | grep -v disconnected | grep connected | awk '{print $2}' | uniq | head -n1)" | ||
+ | [ ${ACTIVE_TYPE_1} == "gsm" ] && ACTIVE_DEVICE_1="ppp0" | ||
+ | |||
+ | ACTIVE_DEVICE_2="$(nmcli dev status | grep -v disconnected | grep connected | grep -v ${IGNORE_DEV} | awk '{print $1}' | uniq | tail -n1)" | ||
+ | ACTIVE_TYPE_2="$(nmcli dev status | grep -v disconnected | grep connected | awk '{print $2}' | uniq | tail -n1)" | ||
+ | [ ${ACTIVE_TYPE_2} == "gsm" ] && ACTIVE_DEVICE_2="ppp0" | ||
+ | |||
+ | |||
+ | if [ ${ACTIVE_TYPE_1} == "" ] | ||
+ | then | ||
+ | break | ||
+ | else | ||
+ | ACTIVE_IP_1="$(ifconfig ${ACTIVE_DEVICE_1} | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | uniq | cut -f1)" | ||
+ | echo ${ACTIVE_IP_1} > ${DEV_IP} | ||
+ | echo ${ACTIVE_DEVICE_1} > ${ADEV} | ||
+ | fi | ||
+ | |||
+ | if [ ${ACTIVE_TYPE_2} == "" ] | ||
+ | then | ||
+ | break | ||
+ | else | ||
+ | ACTIVE_IP_2="$(ifconfig ${ACTIVE_DEVICE_2} | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | uniq | cut -f1)" | ||
+ | echo ${ACTIVE_IP_2} > ${DEV_IP2} | ||
+ | echo ${ACTIVE_DEVICE_2} > ${ADEV2} | ||
+ | fi | ||
+ | |||
+ | ######################################################################################## | ||
+ | ######################################################################################## | ||
+ | ## COMPARE STATES | ||
+ | ######################################################################################## | ||
+ | |||
+ | ######################################################################################## | ||
+ | # Compare public internet ip | ||
+ | gotip=$(cat ${GOT_IP}) | ||
+ | compare_getip=$(cat ${WORKING_IP}) | ||
+ | |||
+ | if [[ "$compare_getip" != "$gotip" ]] | ||
+ | then | ||
+ | echo "######################################" | ||
+ | |||
+ | if [ "${gotip}" == "" ] | ||
+ | then | ||
+ | echo "NO INTERNET CONNECTION" | ||
+ | else | ||
+ | echo "INTERNET IP CHANGED on ${ACTIVE_DEVICE_1} : ${ACTIVE_IP_1} to ${gotip}" | ||
+ | fi | ||
+ | |||
+ | cp ${GOT_IP} ${WORKING_IP} | ||
+ | on_internet_adress_change | ||
+ | |||
+ | else | ||
+ | [ "${gotip}" == "" ] && echo "NO INTERNET CONNECTION" | ||
+ | [ ${ACTIVE_DEVICE_1} != "" ] && echo "Internet IP not changed on ${ACTIVE_DEVICE_1} : ${ACTIVE_IP_1} is ${gotip}" | ||
+ | fi | ||
+ | |||
+ | |||
+ | ######################################################################################## | ||
+ | # Compare first local device | ||
+ | |||
+ | devip=$(cat ${DEV_IP}) | ||
+ | compare_devip=$(cat ${WORKING_DEV_IP}) | ||
+ | |||
+ | if [[ "$compare_devip" != "$devip" ]] | ||
+ | then | ||
+ | echo "######################################" | ||
+ | echo "IP OF DEVICE 1 CHANGED: ${ACTIVE_DEVICE_1} to ${ACTIVE_IP_1}" | ||
+ | cp ${DEV_IP} ${WORKING_DEV_IP} | ||
+ | on_local_address_change | ||
+ | |||
+ | else | ||
+ | [ "${gotip}" == "" ] && echo "NO INTERNET CONNECTION" | ||
+ | [ ${ACTIVE_DEVICE_1} == "" ] && echo "Local IP not changed on ${ACTIVE_DEVICE_1} : ${ACTIVE_IP_1}" | ||
+ | fi | ||
+ | |||
+ | |||
+ | ######################################################################################## | ||
+ | # Compare second local device | ||
+ | |||
+ | devip2=$(cat ${DEV_IP2}) | ||
+ | compare_devip2=$(cat ${WORKING_DEV_IP2}) | ||
+ | |||
+ | if [[ "$compare_devip2" != "$devip2" ]] | ||
+ | then | ||
+ | echo "######################################" | ||
+ | echo "IP OF DEVICE 2 CHANGED: ${ACTIVE_DEVICE_2} to ${ACTIVE_IP_2}" | ||
+ | cp ${DEV_IP2} ${WORKING_DEV_IP2} | ||
+ | on_local_address_change | ||
+ | |||
+ | else | ||
+ | [ "${gotip}" == "" ] && echo "NO INTERNET CONNECTION" | ||
+ | [ ${ACTIVE_DEVICE_2} == "" ] && echo "Local IP not changed on ${ACTIVE_DEVICE_2} : ${ACTIVE_IP_2}" | ||
+ | fi | ||
+ | |||
+ | ######################################################################################## | ||
+ | # ROUTING | ||
+ | ACTIVE_GATEWAY_DEV="$(route | grep default | awk '{print $8}')" | ||
+ | echo ${ACTIVE_GATEWAY_DEV} > ${GW_DEV} | ||
+ | |||
+ | gwdev=$(cat ${GW_DEV}) | ||
+ | compare_gwdev=$(cat ${WORKING_GW_DEV}) | ||
+ | |||
+ | # compare ROUTING | ||
+ | if [[ "$compare_gwdev" != "$gwdev" ]] | ||
+ | then | ||
+ | echo "######################################" | ||
+ | echo "DEFAUTL GATEWAY CHANGED to new device ${ACTIVE_DEVICE_1} to ${ACTIVE_IP_1}" | ||
+ | cp ${GW_DEV} ${WORKING_GW_DEV} | ||
+ | on_gw_change | ||
+ | |||
+ | else | ||
+ | [ "${gotip}" == "" ] && echo "NO INTERNET CONNECTION" | ||
+ | [ ${ACTIVE_DEVICE_1} == "" ] && echo "DEFAULT GATEWAY not changed on ${ACTIVE_GW_DEV}" | ||
+ | fi | ||
+ | |||
+ | |||
+ | sleep 10 | ||
+ | |||
+ | done | ||
= Network Manager = | = Network Manager = |
Revision as of 16:55, 7 January 2014
Contents
Own internet ip
curl -s http://www.ipchicken.com/ | awk '/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/ {print $1}' | uniq
Own local ip
all ip's:
ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'
or for a particualar interface:
ifconfig wlan0 | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'
or:
alias myip="ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'"
Montitor ip changes
BIG script, inspired by some others ...
This script monitors a maximum of two simultanuisly connnections out of one of these
- ppp0
- wlan0
- eth0
It reports changes on
- name and ip of each interface
- default router
It can be used to fine tune network issues.
#!/bin/bash export LC_MESSAGES="en_US.UTF-8" export LC_TYPE="en_US.UTF-8" export LANGUAGE="en_US.UTF-8" IGNORE_DEV="virbr0|tun0" WORKING_IP="/tmp/workingip.txt" GOT_IP="/tmp/gotip.txt" DEV_IP="/tmp/devip.txt" ADEV="/tmp/adev.txt" WORKING_DEV_IP="/tmp/wdevip.txt" DEV_IP2="/tmp/devip2.txt" ADEV2="/tmp/adev2.txt" WORKING_DEV_IP2="/tmp/wdevip2.txt" DEV="/tmp/dev.txt" GW_DEV="/tmp/gwdev.txt" WORKING_GW_DEV="/tmp/wgwdev.txt" # When the gateway of the system changes, do ... on_gw_change() { echo "gateyway changed." } # When the public internet address of the system changes, do ... on_internet_adress_change() { echo "public ip changed." } # When the local address of your network card(s) changes on_local_address_change() { echo "local ip address changed." } # watch -n2 "echo -n 'WRK:'; cat /tmp/workingip.txt ;echo -n 'GOT:'; cat /tmp/gotip.txt ; echo -n 'DIP:'; cat /tmp/devip.txt; echo -n 'ADEV:'; cat /tmp/adev.txt; echo -n 'WDEV:'; cat /tmp/wdevip.txt; echo -n 'GWDEV:'; cat /tmp/gwdev.txt; echo -n 'WGWDEV:'; cat /tmp/wgwdev.txt;" # Initiate first dig @ns1.google.com 2> /dev/null 1> /dev/null && myip="$(dig @ns1.google.com -t txt o-o.myaddr.l.google.com +short | sed s/\"/\/g)" # myip=$(curl -s http://www.ipchicken.com/ | awk '/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/ {print $1}' | uniq | grep -v curl) # requires stun: # apt-get install stun # sudo service stun stop # sudo update-rc.d -f stun remove #myip=$(stun -v stunserver.org 2>&1 1>/dev/null | grep MappedAddress | sed -e 's/.*MappedAddress = //' -e 's/:.*//' | uniq) echo ${myip} > ${GOT_IP} cp ${GOT_IP} ${WORKING_IP} ACTIVE_DEVICE_1="$(nmcli dev status | grep -v disconnected | grep connected | grep -v ${IGNORE_DEV} | awk '{print $1}' | uniq | head -n1)" ACTIVE_TYPE_1="$(nmcli dev status | grep -v disconnected | grep connected | awk '{print $2}' | uniq | head -n1)" [ ${ACTIVE_TYPE_1} == "gsm" ] && ACTIVE_DEVICE_1="ppp0" ACTIVE_DEVICE_2="$(nmcli dev status | grep -v disconnected | grep connected | grep -v ${IGNORE_DEV} | awk '{print $1}' | uniq | tail -n1)" ACTIVE_TYPE_2="$(nmcli dev status | grep -v disconnected | grep connected | awk '{print $2}' | uniq | tail -n1)" [ ${ACTIVE_TYPE_2} == "gsm" ] && ACTIVE_DEVICE_2="ppp0" mygw_dev="$(route | grep default | awk '{print $8}')" echo ${mygw_dev} > ${GW_DEV} cp ${GW_DEV} ${WORKING_GW_DEV} #A Actuve devices if [ ${ACTIVE_TYPE_1} == "" ] then echo "NO ACTIVE DEVICE" else ACTIVE_IP_1="$(ifconfig ${ACTIVE_DEVICE_1} | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | uniq)" echo ${ACTIVE_IP_1} > ${DEV_IP} echo ${ACTIVE_DEVICE_1} > ${ADEV} cp ${DEV_IP} ${WORKING_DEV_IP} fi # There is not second device if [ "${ACTIVE_DEVICE_1}" == "${ACTIVE_DEVICE_2}" ] then echo "NO ACTIVE SECOND DEVICE" echo "" > ${DEV_IP2} echo "" > ${ADEV2} cp ${DEV_IP} ${WORKING_DEV_IP2} else if [ ${ACTIVE_TYPE_2} == "" ] then echo "NO ACTIVE SECOND DEVICE" else ACTIVE_IP_1="$(ifconfig ${ACTIVE_DEVICE_2} | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | uniq)" echo ${ACTIVE_IP_1} > ${DEV_IP2} echo ${ACTIVE_DEVICE_2} > ${ADEV2} cp ${DEV_IP} ${WORKING_DEV_IP2} fi fi sleep 1 # MAIN while (true); do #export LC_MESSAGES="en_US.UTF-8" #export LC_TYPE="en_US.UTF-8" # Check the gotten internet IP #getip=$(curl -s http://www.ipchicken.com/ | awk '/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/ {print $1}' | uniq | grep -v curl) dig @ns1.google.com 2> /dev/null 1> /dev/null && getip="$(dig @ns1.google.com -t txt o-o.myaddr.l.google.com +short | sed s/\"/\/g)" echo ${getip} > ${GOT_IP} # Check the lokal IP and interfaces # Get the active device from network manager ACTIVE_DEVICE_1="$(nmcli dev status | grep -v disconnected | grep connected | grep -v ${IGNORE_DEV} | awk '{print $1}' | uniq | head -n1)" ACTIVE_TYPE_1="$(nmcli dev status | grep -v disconnected | grep connected | awk '{print $2}' | uniq | head -n1)" [ ${ACTIVE_TYPE_1} == "gsm" ] && ACTIVE_DEVICE_1="ppp0" ACTIVE_DEVICE_2="$(nmcli dev status | grep -v disconnected | grep connected | grep -v ${IGNORE_DEV} | awk '{print $1}' | uniq | tail -n1)" ACTIVE_TYPE_2="$(nmcli dev status | grep -v disconnected | grep connected | awk '{print $2}' | uniq | tail -n1)" [ ${ACTIVE_TYPE_2} == "gsm" ] && ACTIVE_DEVICE_2="ppp0" if [ ${ACTIVE_TYPE_1} == "" ] then break else ACTIVE_IP_1="$(ifconfig ${ACTIVE_DEVICE_1} | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | uniq | cut -f1)" echo ${ACTIVE_IP_1} > ${DEV_IP} echo ${ACTIVE_DEVICE_1} > ${ADEV} fi if [ ${ACTIVE_TYPE_2} == "" ] then break else ACTIVE_IP_2="$(ifconfig ${ACTIVE_DEVICE_2} | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | uniq | cut -f1)" echo ${ACTIVE_IP_2} > ${DEV_IP2} echo ${ACTIVE_DEVICE_2} > ${ADEV2} fi ######################################################################################## ######################################################################################## ## COMPARE STATES ######################################################################################## ######################################################################################## # Compare public internet ip gotip=$(cat ${GOT_IP}) compare_getip=$(cat ${WORKING_IP}) if "$compare_getip" != "$gotip" then echo "######################################" if [ "${gotip}" == "" ] then echo "NO INTERNET CONNECTION" else echo "INTERNET IP CHANGED on ${ACTIVE_DEVICE_1} : ${ACTIVE_IP_1} to ${gotip}" fi cp ${GOT_IP} ${WORKING_IP} on_internet_adress_change else [ "${gotip}" == "" ] && echo "NO INTERNET CONNECTION" [ ${ACTIVE_DEVICE_1} != "" ] && echo "Internet IP not changed on ${ACTIVE_DEVICE_1} : ${ACTIVE_IP_1} is ${gotip}" fi ######################################################################################## # Compare first local device devip=$(cat ${DEV_IP}) compare_devip=$(cat ${WORKING_DEV_IP}) if "$compare_devip" != "$devip" then echo "######################################" echo "IP OF DEVICE 1 CHANGED: ${ACTIVE_DEVICE_1} to ${ACTIVE_IP_1}" cp ${DEV_IP} ${WORKING_DEV_IP} on_local_address_change else [ "${gotip}" == "" ] && echo "NO INTERNET CONNECTION" [ ${ACTIVE_DEVICE_1} == "" ] && echo "Local IP not changed on ${ACTIVE_DEVICE_1} : ${ACTIVE_IP_1}" fi ######################################################################################## # Compare second local device devip2=$(cat ${DEV_IP2}) compare_devip2=$(cat ${WORKING_DEV_IP2}) if "$compare_devip2" != "$devip2" then echo "######################################" echo "IP OF DEVICE 2 CHANGED: ${ACTIVE_DEVICE_2} to ${ACTIVE_IP_2}" cp ${DEV_IP2} ${WORKING_DEV_IP2} on_local_address_change else [ "${gotip}" == "" ] && echo "NO INTERNET CONNECTION" [ ${ACTIVE_DEVICE_2} == "" ] && echo "Local IP not changed on ${ACTIVE_DEVICE_2} : ${ACTIVE_IP_2}" fi ######################################################################################## # ROUTING ACTIVE_GATEWAY_DEV="$(route | grep default | awk '{print $8}')" echo ${ACTIVE_GATEWAY_DEV} > ${GW_DEV} gwdev=$(cat ${GW_DEV}) compare_gwdev=$(cat ${WORKING_GW_DEV}) # compare ROUTING if "$compare_gwdev" != "$gwdev" then echo "######################################" echo "DEFAUTL GATEWAY CHANGED to new device ${ACTIVE_DEVICE_1} to ${ACTIVE_IP_1}" cp ${GW_DEV} ${WORKING_GW_DEV} on_gw_change else [ "${gotip}" == "" ] && echo "NO INTERNET CONNECTION" [ ${ACTIVE_DEVICE_1} == "" ] && echo "DEFAULT GATEWAY not changed on ${ACTIVE_GW_DEV}" fi sleep 10 done
Network Manager
Status of all devices
export LC_MESSAGES="en_US@.UTF-8" \ export LC_TYPE="en_US.UTF-8" \ nmcli dev status
Testing network performance
There are a lot of possibilities to messure the network throughput on *nix machines. Some of the most valuable I am going to sumup in this article. Please read the corresponding links for further explanation at the end.
netperf
Installation:
sudo apt-get install netperf sudo apt-get install ethstatus
Start netperf as a daemon (ubuntu / debian way)
sudo /etc/init.d/netperf start
Open a seperate terminal.
ethstatus -i eth0
Then start from the server...
netperf -H ip_of_client
...and vice versa on client
netperf -H ip_of_server
The last column will show the througput in (power of ten)-bits/sec (which has to be divided through 8 to get byte/sec)
netcat
First approach
From client machine to server ...
On server:
netcat -l -p 1234 > /dev/null
On client:
dd if=/dev/zero bs=1M count=1000 |netcat server 1234
From server to client machine ... On client:
netcat -l -p 1234 > /dev/null
On server:
dd if=/dev/zero bs=1M count=1000 |netcat client 1234
You can exchange /dev/zero with e.g. /dev/md0 (for a raid device) or /dev/sda for testing your harddisk performance.
Second approach
1st computer. (The Server)
nc -v -v -l -n -p 5096 >/dev/null
2nd computer. (The Client)
time yes|nc -v -v -n 192.168.1.1 5096 >/dev/null Ctrl+C
On the server note the rcvd. Multiply by 8 and divide by the time you see on your client. This are the maximal (theoretical) MB/s speed you will get for file transfers over the network.
iperf
Messures the network perfomance.
On the server do (start iperf in server mode)
iperf -s
On the client machine do
iperf -c server_ip -i 1 -t 10
Typical values
- 15-25 Mbits/sec for a 54Mbit Wireless LAN
- 300-350 Mbits/sec for a Gigabit LAN
The values depend heavily to
- quality of the network card
- quality of the cable (already CAT 6 !?) or wireless connection
- bus speed
- processor speed
ethtool
Ethtool gives you important informations over your network card, its settings and actual modes:
ethtool eth0
sysctl
Settings for tpc ip settings:
for i in rmem wmem mem; do sysctl net.ipv4.tcp_${i}; done
gives e.g. on an older machine (366MHz AMD K6, 33MHz bus)
net.ipv4.tcp_rmem = 4096 87380 577600 net.ipv4.tcp_wmem = 4096 16384 577600 net.ipv4.tcp_mem = 13536 18050 27072
and on a "newer" system (AMD Athlon XP 2000+, 133MHz bus)
net.ipv4.tcp_rmem = 4096 87380 4194304 net.ipv4.tcp_wmem = 4096 16384 4194304 net.ipv4.tcp_mem = 170592 227456 341184
I can be set with e.g.:
sysctl -w net.ipv4.tcp_wmem="4096 16384 1048576"
But consider: better know what you are doing! On modern linux systems this should not be necessary.
MTU - Jumbo Frames
So called "Jumbo Frames" can reduce the CPU usage on the server. The network throughput is _NOT_ improved very much. Kernel greater than 2.6.17 support frame bigger than 1500 bythes.
Note, that both network card (driver) and used switches must support this kind of settings. Also it is not advisable to use this above large networks (internet connection might suffer). Better use this for direct connection between seperate NICs. Test e.g with
ifconfig eth0 mtu 9044; echo -- DO SOME TESTS NOW --; sleep 120; ifconfig eth0 mtu 16436
16436 is the default setting on actual systems. Other good values seem to be 4022
Network configuration files /etc/sysconfig/network-script/ifcfg-eth0 (CentOS / RHEL / Fedora Linux)
MTU=9044
Debian / Ubuntu Linux use /etc/network/interfaces configuration file.
mtu 9044
Test with
/etc/init.d/networking restart ip route get IP-address
Comparing with real (hard)drive performance
If you like to get the real disk perfance use e.g.
dd if=/dev/zero of=3_2-GIG-file bs=1M count=3096
or
dd if=/dev/sda of=/dev/null bs=1M Ctrl + C
or read a file from a mounted directory
dd if=a_huge_file of=/dev/null bs=1M
or with hdparm (the buffered disk read is for interest!):
hdparm -tT /dev/disk
For realistic results you should also consider local disk read/writes for the operating system, other running tasks and that all components share the same (!) PCI bus. For that reason you have to sum up disk usage and network usage.
NFS performance
Mount options
For gigabit networks
rsize=32768,wsize=32768 rsize=65536,wsize=65536
See [5], [7]
Seperate NICs
If you like to use two seperate NICs on an extra private subnet, e.g. 10.0.0.0/24 (25.255.255.0) to communicate for NFS, you should disable the packet forwarding in /proc/sys/net/ipv4/ip_forward
sudo echo 0 >> /proc/sys/net/ipv4/ip_forward
Add the according NIC to your /etc/host
10.0.0.10 mynfsserver 10.0.0.1 mynfsclient1
TIP: You don't have to use a switch instead of a crossover cable connecting two PCs for Gigabit connection. There is merely no difference in performance. For gigabit (!) you don't even have to use a crossover cable because the standard supports using normal cables!
Links
- Main insperation for this articele: 1. linuxquestions.org - gigabit ethernet performance
- 2. Linux User (GER) - Highspeed-LAN mit Gigabit Ethernet, Schnelle Netze
- 3. Jumbo Frames
- 4. A thread about performance issues regarding NFS/SMB with gigabit at ubuntuforums.com
- 5. Arch Linux - Nfs
- 6. Linuxstreet.net - Articles related to gigabit
- 7. Linux.com - How much can you improve network throughput with a high-end NIC?
- 8. VDRPortal (GER)
- 9. linuxhomenetworking.com