Tuesday 15 August 2023

how to check or modify the network card speed in ubuntu?

ref: https://phoenixnap.com/kb/ethtool-command-change-speed-duplex-ethernet-card-linux

sudo apt install ethtool

sudo ethtool enp4s0 

sudo ethtool -s enp4s0 autoneg on speed 1000 duplex full

sudo ethtool enp4s0 


Settings for enp4s0:

Supported ports: [ TP ]

Supported link modes:   10baseT/Half 10baseT/Full 

                        100baseT/Half 100baseT/Full 

                        1000baseT/Full 

Supported pause frame use: Symmetric Receive-only

Supports auto-negotiation: Yes

Supported FEC modes: Not reported

Advertised link modes:  10baseT/Half 10baseT/Full 

                        100baseT/Half 100baseT/Full 

                        1000baseT/Full 

Advertised pause frame use: No

Advertised auto-negotiation: Yes

Advertised FEC modes: Not reported

Link partner advertised link modes:  10baseT/Half 10baseT/Full 

                                     100baseT/Half 100baseT/Full 

                                     1000baseT/Full 

Link partner advertised pause frame use: No

Link partner advertised auto-negotiation: Yes

Link partner advertised FEC modes: Not reported

Speed: 10Mb/s

Duplex: Full

Port: Twisted Pair

PHYAD: 0

Transceiver: internal

Auto-negotiation: on

MDI-X: Unknown

Supports Wake-on: pumbg

Wake-on: g

Current message level: 0x00000033 (51)

       drv probe ifdown ifup

Link detected: yes


Wednesday 2 August 2023

How to check ping able IP address in total using a bash script?

Create a bash script as following:-

#!/bin/bash
# Array of IP addresses to ping
ip_addresses=(
192.168.1.1
192.168.1.2
192.168.1.3
)
# Variables to count successful and unsuccessful pings
ping_success=0
ping_fail=0
# Function to perform the ping and update the counters
ping_ips() {
for ip in "${ip_addresses[@]}"; do
ping -c 1 "$ip" > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Ping to $ip succeeded"
((ping_success++))
else
echo "Ping to $ip failed"
((ping_fail++))
fi
done
}
# Call the function
ping_ips
# Print the results
echo "Total IPs: ${#ip_addresses[@]}"
echo "Ping Success: $ping_success"
echo "Ping Fail: $ping_fail"