Skip to content

Instantly share code, notes, and snippets.

@Lirt
Last active August 8, 2023 07:15
Show Gist options
  • Save Lirt/7a3811c30fb49b5269dc1251f39eee9f to your computer and use it in GitHub Desktop.
Save Lirt/7a3811c30fb49b5269dc1251f39eee9f to your computer and use it in GitHub Desktop.
Useful things with linux networking
# Debian default gateway /etc/network/interfaces
up route add default gw 62.210.123.1
# Force interface eth0 to 10 Gbit speed
ethtool -s <device> speed 10000 duplex full autoneg off
# For the setting to be persistent across reboots
# edit "/etc/udev/rules.d/71-ethtool.rules"ff and
# add "SUBSYSTEM=="net", ACTION=="add", NAME=="<device>", RUN+="/sbin/ethtool <device> -s speed 100 duplex full autoneg off"
# Traffic shaping libvirt / Quality of service
<devices>
<interface type='network'>
<source network='default'/>
<target dev='vnet0'/>
<bandwidth>
<inbound average='1000' peak='5000' floor='200' burst='1024'/>
<outbound average='128' peak='256' burst='256'/>
</bandwidth>
</interface>
</devices>
# Get HW address of interface. Split by ':'
interface="eth0"
cat /sys/class/net/$interface/address
# Get operational state of interface (up/down/unknown)
cat /sys/class/net/$interface/operstate
# Get carrier status of network interface (interface must be up).
# 0 if interface is DOWN
# 1 if interface is UP
cat /sys/class/net/$interface/carrier
iptables -nL | grep -Eo "[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}" | sort | uniq | xargs -I {} -P 50 ping -W1 -c1 {} | grep -B1 "0 received"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment