Networking: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (10 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
[[Category:networking]] | [[Category:networking]] | ||
[[Category:Linux/Unix]] | [[Category:Linux/Unix]] | ||
=Basics= | |||
For IP networks there are 2 address schemes, [[IPv4]] and [[IPv6]] | |||
;ping <address> | |||
:Get response from <address> interface | |||
;<code>for i in $(seq 1 254); do ping -c1 -t 1 10.117.192.$i; done</code> | |||
:Scan a subnet | |||
=Check network connectivity= | =Check network connectivity= | ||
;netstat - | ;netstat -na # deprecated | ||
:Show port status (LISTEN, ESTABLISHED, .....) | ;ss -na | ||
:Show port status (LISTEN, ESTABLISHED, .....) | |||
:If you are root -p adds the process that owns the socket | |||
;<code>nc -v -z <host> <port></code> | ;<code>nc -v -z <host> <port></code> | ||
| Line 40: | Line 49: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=Interfaces= | =Interfaces= | ||
;ifconfig -a | ;ifconfig -a # Deprecated, replaced by ip | ||
:Show all network interfaces | :Show all network interfaces | ||
| Line 50: | Line 57: | ||
:Assign <ipaddress> to <interface> | :Assign <ipaddress> to <interface> | ||
;ip | ;ip address | ||
;ip | :Show all IP addresses | ||
:Show all | ;ip -6 address | ||
:Show all IPv6 addresses | |||
;ip -6 addr add <ipv6address>/<prefixlength> dev <interface> | ;ip -6 addr add <ipv6address>/<prefixlength> dev <interface> | ||
| Line 62: | Line 68: | ||
:Show interface link status (speed) | :Show interface link status (speed) | ||
When not using confusing things like [[NetworkManager]] network configuration is controlled by the interfaces file. | |||
;/etc/network/interfaces | |||
<syntaxhighlight lang=text> | |||
auto <interface> # Boot process waits until the interface is up or a time-out (5 minutes) | auto <interface> # Boot process waits until the interface is up or a time-out (5 minutes) | ||
allow-hotplug <interface> # Boot process does not wait for the interface. | allow-hotplug <interface> # Boot process does not wait for the interface. | ||
| Line 72: | Line 77: | ||
wpa-psk <password> | wpa-psk <password> | ||
# To have ipv6 | # For static ipv4 | ||
interface <interface> inet static | |||
address xxx.xxx.xxx.xxx/<masklen> | |||
gateway xxx.xxx.xxx.xxx | |||
# To have ipv6 auto-configured (by SLAAC) | |||
iface <interface> inet6 auto | |||
# To have ipv6 auto-configured (by SLAAC) and add own address | |||
iface <interface> inet6 static | iface <interface> inet6 static | ||
address unique:local:address:prefix:your:own:host:address | address unique:local:address:prefix:your:own:host:address | ||
| Line 83: | Line 95: | ||
netmask 64 | netmask 64 | ||
# To have ipv6 | # To have ipv6 auto-configured (by SLAAC) and query a dhcp-server | ||
iface <interface> inet6 dhcp | iface <interface> inet6 dhcp | ||
autoconf 1 | autoconf 1 | ||
| Line 91: | Line 103: | ||
:vi /etc/modprobe.d/blackllst.conf | :vi /etc/modprobe.d/blackllst.conf | ||
:Put in the driver for your interface like: <code>blacklist ath9k</code> | :Put in the driver for your interface like: <code>blacklist ath9k</code> | ||
=Wireless= | |||
;iwscan <interface> scanning | |||
:Show available accesspoints | |||
;iwconfig <interface> | |||
:Show details of the wireless connection | |||
=Routing= | =Routing= | ||
;route add -net default gw <IPaddress> | ;route add -net default gw <IPaddress> # Deprecated | ||
;ip route add -net default gw <IPaddress> | |||
:Add a default route using <IPaddress> as gateway | :Add a default route using <IPaddress> as gateway | ||
| Line 104: | Line 123: | ||
=Tracing= | =Tracing= | ||
For tracing traffic see [[Tcpdump]] | For tracing traffic see [[Tcpdump]] | ||
;traceroute <destination> | |||
:Show which route a package takes to reach destination | |||
;ip route get <IPaddress> | |||
:Show the interface used to go to <IPaddress> | |||
To get just the interface name you can use this[https://unix.stackexchange.com/questions/14961/how-to-find-out-which-interface-am-i-using-for-connecting-to-the-internet]: | |||
<syntaxhighlight lang=bash> | |||
host=<fqdn> | |||
host_ip=$(getent ahosts "$host" | awk '{print $1; exit}') | |||
ip route get "$host_ip" | grep -Po '(?<=(dev ))(\S+)' | |||
</syntaxhighlight> | |||
=Other= | =Other= | ||
;<code>wget <URL></code> | ;<code>wget <URL></code> | ||
:Get the data from <URL> | :Get the data from <URL> | ||
Latest revision as of 20:17, 4 January 2026
Basics
For IP networks there are 2 address schemes, IPv4 and IPv6
- ping <address>
- Get response from <address> interface
for i in $(seq 1 254); do ping -c1 -t 1 10.117.192.$i; done- Scan a subnet
Check network connectivity
- netstat -na # deprecated
- ss -na
- Show port status (LISTEN, ESTABLISHED, .....)
- If you are root -p adds the process that owns the socket
nc -v -z <host> <port>- Netcat: Tell me if we can open a connection to <host> on <port>. Without -z it works like telnet
nc -v -u -z <host> <port>- Tell me if we can open a connection to <host> on a UDP <port>
curl -vvv -k --proxy1.0 <proxyIP>:<proxyPort> <Remote URL>- Get the data from <remote URL> via <proxyIP> -k allows insecure SSL connections
curl -vvv telnet://<IP>:<port>- Just test connectivity to a port
#!/bin/bash
PORT=$1
TARGETS="999.999.999.999
888.888.888.888
777.777.777.777
666.666.666.666
"
for TARGET in ${TARGETS}
do
curl http://${TARGET}:${PORT} --connect-timeout 1 > /dev/null 2>&1
if [ $? == 28 ] # 28 is the curl code for connection timeout
then
echo No connection to ${TARGET}:${PORT}
fi
done
Interfaces
- ifconfig -a # Deprecated, replaced by ip
- Show all network interfaces
- ifconfig <interface> <ipaddress>
- Assign <ipaddress> to <interface>
- ip address
- Show all IP addresses
- ip -6 address
- Show all IPv6 addresses
- ip -6 addr add <ipv6address>/<prefixlength> dev <interface>
- Add an IPv6 address to <interface>
- mii-tool <interface>
- Show interface link status (speed)
When not using confusing things like NetworkManager network configuration is controlled by the interfaces file.
- /etc/network/interfaces
auto <interface> # Boot process waits until the interface is up or a time-out (5 minutes)
allow-hotplug <interface> # Boot process does not wait for the interface.
iface <interface> inet dhcp
wpa-ssid <ssid>
wpa-psk <password>
# For static ipv4
interface <interface> inet static
address xxx.xxx.xxx.xxx/<masklen>
gateway xxx.xxx.xxx.xxx
# To have ipv6 auto-configured (by SLAAC)
iface <interface> inet6 auto
# To have ipv6 auto-configured (by SLAAC) and add own address
iface <interface> inet6 static
address unique:local:address:prefix:your:own:host:address
autoconf 1
netmask 64
# Add another address to <interface>(work for IPv4 addresses too
iface <interface> inet6 static
address unique:local:address:prefix:your:own:host:address
netmask 64
# To have ipv6 auto-configured (by SLAAC) and query a dhcp-server
iface <interface> inet6 dhcp
autoconf 1
- Disable an interface completely (even not shown by ifconfig)
- vi /etc/modprobe.d/blackllst.conf
- Put in the driver for your interface like:
blacklist ath9k
Wireless
- iwscan <interface> scanning
- Show available accesspoints
- iwconfig <interface>
- Show details of the wireless connection
Routing
- route add -net default gw <IPaddress> # Deprecated
- ip route add -net default gw <IPaddress>
- Add a default route using <IPaddress> as gateway
Tunneling
ssh -L 8080:remotehost:3006 proxy- Login over ssh to proxy and there connect to remotehost port 3006. Connect local port 8080 to the remote connection.
- Now if you connect to port 8080 on your local server you are connected to port 3006 on the remotehost
- Using
-nNTprevents that the ssh command opens a terminal on the proxy. The ssh command however must remain active.
Tracing
For tracing traffic see Tcpdump
- traceroute <destination>
- Show which route a package takes to reach destination
- ip route get <IPaddress>
- Show the interface used to go to <IPaddress>
To get just the interface name you can use this[1]:
host=<fqdn>
host_ip=$(getent ahosts "$host" | awk '{print $1; exit}')
ip route get "$host_ip" | grep -Po '(?<=(dev ))(\S+)'
Other
wget <URL>- Get the data from <URL>