Linux Networking Part 1
Posted by hsukumar on July 4, 2008
- # ethtool eth0 # Show the ethernet status (replaces mii-diag)
# ethtool -s eth0 speed 100 duplex full # Force 100Mbit Full duplex
# ethtool -s eth0 autoneg off # Disable auto negotiation
# ethtool -p eth1 # Blink the ethernet led – very useful when supported
# ip link show # Display all interfaces on Linux (similar to ifconfig)
# ip link set eth0 up # Bring device up (or down). Same as “ifconfig eth0 up”
# ip addr show # Display all IP addresses on Linux (similar to ifconfig)
# ip neigh show # Similar to arp -a
Routing
Print routing table
# route -n # Linux or use “ip route”
# netstat -rn # Linux, BSD and UNIX
# route print # Windows
Add and delete a route
# route add -net 192.168.20.0 netmask 255.255.255.0 gw 192.168.16.254
# ip route add 192.168.20.0/24 via 192.168.16.254 # same as above with ip route
# route add -net 192.168.20.0 netmask 255.255.255.0 dev eth0
# route add default gw 192.168.51.254
# ip route add default via 192.168.51.254 dev eth0 # same as above with ip route
# route delete -net 192.168.20.0 netmask 255.255.255.0
Windows
# Route add 192.168.50.0 mask 255.255.255.0 192.168.51.253
# Route add 0.0.0.0 mask 0.0.0.0 192.168.51.254
Configure additional IP addresses
# ifconfig eth0 192.168.50.254 netmask 255.255.255.0 # First IP
# ifconfig eth0:0 192.168.51.254 netmask 255.255.255.0 # Second IP
# ip addr add 192.168.50.254/24 dev eth0 # Equivalent ip commands
# ip addr add 192.168.51.254/24 dev eth0 label eth0:1
Change MAC address
Normally you have to bring the interface down before the change. Don’t tell me why you want to change the MAC address…
# ifconfig eth0 down
# ifconfig eth0 hw ether 00:01:02:03:04:05 # Linux
# ifconfig fxp0 link 00:01:02:03:04:05 # FreeBSD
# ifconfig hme0 ether 00:01:02:03:04:05 # Solaris
# sudo ifconfig en0 ether 00:01:02:03:04:05 # Mac OS X Tiger
# sudo ifconfig en0 lladdr 00:01:02:03:04:05 # Mac OS X Leopard
There are many tools for windows that can do this job for you with out typing commands like for example etherchange and so on
Ports in use
Listening open ports:
- # netstat -an | grep LISTEN
- # lsof -i # Linux list all Internet connections
- # socklist # Linux display list of open sockets
- # sockstat -4 # FreeBSD application listing
- # netstat -anp –udp –tcp | grep LISTEN # Linux
- # netstat -tup # List active connections to/from system (Linux)
- # netstat -tupl # List listening ports from system (Linux)
- # netstat -ano # Windows