network
Please also see iptables
Show ip all
ip a
Show network links
ip link show
ip link ls up
networkctl list
networkctl status
bridge link show
Show IP address
ip addr show
ip -d addr show eth0
Add IP address
ip addr add 10.0.10.15/24 brd 10.0.10.255 dev eth0
Enable network device
ip link set dev eth0 up
Show IP route
ip route show
Show ip default gateway
ip -br route | grep default
Add IP route
ip route add 192.168.1.0/24 via 10.0.99.1
Show TCP ports
ss -netpa
Show UDP ports
ss -neupa
Show firwall rules
iptables -L -v -n
Show ip forward setting
sysctl -a | grep forward
Show DNS setting
resolvectl status
Show IP of DNS server
resolvectl | grep 'DNS Servers'
Show IP of DHCP server
dhclient -d -nw eth0 | grep DHCPOFFER
journalctl | grep -Ei 'DHCPv4 address'
netplan ip leases eth0
Get external ip
curl ifconfig.me
Get NS record
dig +short NS dns.google
Get A record
dig +short A dns.google
Get PTR record
dig +noall +answer -x 8.8.8.8
Get DNS server
dig @1.1.1.1 bash.cyberciti.biz
Clear DNS cache
systemd-resolve --flush-caches
Loopback
127.0.0.1
is a special loopback interface on Linux hosts. It's only reachable for applications running on the same host.
0.0.0.0
is shorthand for all interfaces.
https://wiki.archlinux.org/title/Network_configuration
Address types
-
loopback
- IPv4: 127.0.0.0/8
- IPv6: ::1/128
-
link-local
- IPv4: 169.254.0.0/16 and 224.0.0.0/24
- IPv6: fe80::/64
Test TCP port open
nc -zv 192.168.1.15 22
TCP open port and sent data
# Machine 1:
nc -l -p 6666
#Machine 2:
echo hello | nc 192.168.120.214 6666
Please make sure firewall rules are open.
Test LDAPS network port
nc <ldapserverip> 636 -v -w 60
nc Ncat: No route to host.
$ echo hello | nc 192.168.120.214 6666
Ncat: No route to host.
$ ping -c1 192.168.120.214
PING 192.168.120.214 (192.168.120.214) 56(84) bytes of data.
64 bytes from 192.168.120.214: icmp_seq=1 ttl=64 time=0.454 ms
--- 192.168.120.214 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.454/0.454/0.454/0.000 ms
The "No route to host" message has nothing to do with network settings and routes. The next "ping" command demonstrates that there is no problem with an unreachable host. Looking closely at the previous nft list command, you can see:
# nft list table inet firewalld
table inet firewalld {
..
reject with icmpx type admin-prohibited
..
The firewall rule rejects access with ICMP message, that cause "No route" error.
ICMP type of admin-prohibited
and host-prohibited
results in No route to host
error displayed at the client.
Example nftables commmands:
nft list tables
nft list table inet firewalld
nft list table ip filter
nft list chains
nft list chain ip filter FORWARD
nft list ruleset
http://www.voleg.info/nft-fw-iptables.html https://iceburn.medium.com/compare-firewalld-iptables-nftables-netfilter-de08a8d21b5b
Process listenting on port
lsof -nP -i :9491
show listening ports
ss -naut
iproute2 utils
ip does not save configuration after reoboot
show all ip
ip a
show physical links
ip link show
show ARP table
ip neighbour show
clear ARP table
ip neighbour flush all
show all routes in all tables
ip route show table all
show route to address
ip route get 1.1.1.1
temporary add ip address to eth0 interface
ip addr add 192.168.1.4/24 brd 192.168.1.255 dev eth0
bring eth0 interface up
ip link set eth0 up
temporary add default route
ip route add default via 192.168.1.1
add VLAN
ip link add link eth0 name eth0.10 type vlan id 10
ip -d link show eth0.10
ip addr add 10.0.10.15/24 brd 10.0.10.255 dev eth0.10
ip link set dev eth0.10 up
netplan (static network cofiguration)
save ip conifugration between reboot
/etc/netplan/01-netcfg.yaml
network:
version: 2
ethernets:
eth0:
dhcp4: true
vlans:
eth0.10:
id: 10
link: eth0
addresses: [10.0.10.15/24]
netplan apply
ip -d addr show eth0.10
netplan LACP link aggregation teaming bond
network:
version: 2
ethernets:
eth0:
dhcp4: false
eth1:
dhcp4: false
bonds:
bond0:
interfaces: [eth0, eth1]
parameters:
mode: 802.3ad
Show process PID that listens to port
lsof -i :80
netstat -tulpan
открыть доступ в фаерволле сервису
firewall-cmd --permanent --zone=public --add-service=http
применить изменения к фаерфоллу
firewall-cmd --reload
FirewallD remove rules that are runtime temporary (fallback to permanents)
firewall-cmd --reload
переместить файл сервиса для фаерволла для редактирования
cp /usr/lib/firewalld/services/[service].xml /etc/firewalld/services/[service].xml
Show firewalld configuration
firewall-cmd --list-all
Show process PID that uses a file
lsof /file/path
Проверка http
$ telnet XXX.XX.XX.XXX 80
GET / HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
Send SMTP mail (test email send from shell)
echo "From: graylog@company.com
To: it@company.com
Subject: This is a test
This is body." | curl --insecure --verbose --ssl-reqd smtp://mail.company.com --mail-from graylog@company.com --mail-rcpt it@company.com --upload-file /dev/stdin
SMTP ports
Type | Encrytpion | Port |
---|---|---|
SMTPS | 465, 2465 | Implicit SSL/TLS (Immediately connects via SSL/TLS) |
STARTTLS | 25, 587, 2587 | Explicit SSL/TLS (First connects via plaintext, then upgrades to SSL/TLS) |
whois domain expiration check
#Get the expiration date
expdate="$(whois $1 | egrep -i 'Registry Expiry Date:|Expiration:|Domain Expiration Date:|Registrar Registration Expiration Date:|expire:|paid-till:|option expiration date:|Expires on|Expiry date:|Expiry Date:|Expiration date:|Expiration Date:|Renewal date:|paid-till:|Domain expires:|renewal date:|expires:|Expires:|Expires On:'| head -1 | sed -r 's!^[^0-9]+!!')"
# Turn it into seconds
expdate="$(date -d"$expdate" +%s)"
# Get the current date in seconds
curdate="$(date +%s)"
# Set exp variable
echo $(((expdate-curdate)/86400))
Set socket maximum connection
/etc/sysctl.conf
net.core.somaxconn=1024
sysctl -p
DNS find PTR record for IP address
nslookup -type=ptr T.T.T.T