Command | Description |
---|---|
arp , arping |
Arp manipulates or displays the kernel's IPv4 network neighbour cache. It can add entries to the table, delete one or display the current content. ARP stands for Address Resolution Protocol, which is used to find the MAC (Media Access Control) address of a network neighbor for a given IPv4 Address. |
ifconfig |
Ifconfig is used to configure the kernel-resident network interfaces. It is used at boot time to set up interfaces as necessary. After that, it is usually only needed when debugging or when system tuning is needed. If no arguments are given, |
ip |
Show/manipulate routing, network devices, interfaces and tunnels. |
netstat |
Netstat prints information about the Linux networking subsystem. |
route |
Route manipulates the kernel's IP routing tables. Its primary use is to set up static routes to specific hosts or networks via an interface after it has been configured with the When the |
Old command (Deprecated) | New command | Description |
---|---|---|
ifconfig -a |
ip a |
List all interfaces (enabled and disabled) |
ifconfig <INT_NAME> down |
ip link set <INT_NAME> down |
Disable interface |
ifconfig <INT_NAME> up |
ip link set <INT_NAME> up |
Enable interface |
ifconfig <INT_NAME> <IP> ifconfig <INT_NAME> netmask 255.255.255.0 ifconfig enp6s0:0 192.168.2.25 |
ip addr add <IP>/24 dev <INT_NAME> |
Assign an IP, netmask, or alias to an interface. In the case of ip /24 is the netmask and is required. dev stands for 'device'. There doesn't seem to be an equivalent aliasing function for ip . |
ifconfig enp6s0 mtu 9000 |
ip link set enp6s0 mtu 9000 |
Set the MTU (Max Transfer Unit) of an interface. In most cases, the optimal value (for a home Internet router) is going to be 1500 . |
netstat |
ss |
Print the active sockets of all configured address families. |
netstat -tulpn |
ss -tulpn |
Print tcp , udp , listening , program , and numeric items. |
netstat -neopa |
ss -neopa |
Print numeric , extend , timers , program , all items. |
netstat -g |
ip maddr |
Print groups |
route |
ip r |
Displays contents of the routing tables. |
route add -net <IP> netmask 255.255.255.0 dev <INT_NAME> |
ip route add <IP>/24 dev <INT_NAME> |
Add a new route to a specific interface. |
route add default gw <IP> |
ip route add default via <IP> |
Adds a default route (which will be used if no other route matches). |
arp -a |
ip neigh |
Use alternate BSD style output format (with no fixed columns). |
arp -v |
ip -s neigh |
Display more verbose output. |
arp -s <IP> <HARDWARE_ADDR> |
ip neigh add <IP> lladdr <HARDWARE_ADDR> dev <INT_NAME> |
Add an entry |
arp -i <INT_NAME> -d <IP> |
ip neigh del <IP> dev <INT_NAME> |
Delete an entry |
Check what networks exist (note that without sudo
you may get different results)
sudo virsh net-list --all
Start or auto-start a network
# start
sudo virsh net-start <NAME>
# auto start
sudo virsh net-autostart <NAME>
The default
network will start up a couple interfaces which can be viewed by running ifconfig -a
.
virbr0
virbr0-nic
dnsmasq
was also started. The config for the default
network is in /var/lib/libvirt/dnsmasq/default.conf
. You can edit the network with
sudo virsh net-edit default
It may prompt to choose your editor. For sudo
commands you'll need to sudo select-editor
.
Note that steps 1, 2, and 5 are only neccessary if you currently have an Ethernet cable plugged in.
- Ensure your current connection is disabled/reset.
# check interfaces (display output with color) ip -c a # disable interface sudo ip link set <INT_NAME> down # verify it's down ip a | grep <INT_NAME> | grep -E 'state [A-Z]+'
- Using
ip -c a
will output results in color which is useful most of the time, but when usinggrep
you won't get the expected results.
- Using
- Remove the assigned IP from the interface
# get the 'inet' IP from ip addr show dev <INT_NAME> # delete IP sudo ip addr del <IP> dev <INT_NAME> # verify no 'inet' is assigned ip addr show dev <INT_NAME> | grep -o -E 'inet [^ ]+'
- This command allows for getting the IP programatically
ip addr show dev <INT_NAME> | grep -o -E 'inet [^ ]+' | awk -v col=2 '{print $col}'
- This command allows for getting the IP programatically
- Disable Network daemons
# check if running (common for Desktop environments) sudo systemctl status NetworkManager | grep 'Active: ' # if so disable sudo systemctl stop NetworkManager # check if running (common in Server environments) sudo systemctl status systemd-networkd | grep 'Active: ' # if so disable sudo systemctl stop systemd-networkd
- Create Bridge interface
# A common convention for the name would be 'br0' sudo ip link add name <BR_INT_NAME> type bridge # bind the Ethernet interface to the Bridge (something like 'eth0' master 'br0') sudo ip link set <ETH_INT_NAME> master <BR_INT_NAME> # Assign an IP to the device (check that the IP isn't already assigned). # 'brd' is the Broadcast range in which it'll accept requests (basically all) sudo ip addr add <IP>/16 dev <BR_INT_NAME> brd 198.168.255.255
- Refer to the CIDR table for common subnets. Helps determine whether to use
/16
,/24
, or something custom.
- Refer to the CIDR table for common subnets. Helps determine whether to use
- Bring interfaces back up
sudo ip link set up <ETH_INT_NAME> sudo ip link set up <BR_INT_NAME>
- Try to ping devices
ping <IP> # IP of device on Local network should work ping google.com # should fail (for now)
- If you run
route
you'll see something similar to below, and that there's no default gateway set up. Which means that anything within the192.168.#.#
range will be accepted, and everything else will be dropped.
It's similar to a Server's middleware or routing accept in reverse. For a Server, generally the routes/middleware are processed in numerical order, so top to bottom (add it first, processed first). Kernel routes are proccessed in reverse, so bottom to top.Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 br0
- If you run
- Add a Default Gateway
sudo route add default gw 192.168.1.1
- If you run the
route
command again you should now have something like
Note thatDestination Gateway Genmask Flags Metric Ref Use Iface default _gateway 0.0.0.0 UG 0 0 0 br0 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 br0
_gateway
is just an internal alias for the IP you originally entered. - You should now be able to run
ping google.com
and get a result.
- If you run the
If you went through the manual steps, run the below to remove that stuff
sudo ip link delete <BR_INT_NAME>
sudo ip link set <ETH_INT_NAME> down
- Switch to
root
Usersudo -i
- Go to folder where custom configs will live
cd /etc/systemd/network
- Create custom configs
vim br.netdev
(Create Bridge interface)[NetDev] Name=br0 Kind=bridge
vim 1-br0-bind.network
(Bind Ethernet to Bridge)[Match] Name=en0 [Network] Bridge=br0
vim 2-br0-dhcp.network
(Call DHCP to give Bridge an IP)[Match] Name=br0 [Network] DHCP=ipv4
- Enable Daemon - there should only be one Network daemon running
sudo systemctl enable systemd-networkd sudo systemctl start systemd-networkd # if it was previously stopped while in the middle of an operation, a restart may be required sudo systemctl restart systemd-networkd
- Running
ip a
should now display that the Bridge was set up and the Ethernet is connected to it.
Prefix size | Network mask | Usable hosts per subnet |
/1 | 128.0.0.0 | 2,147,483,646 |
/2 | 192.0.0.0 | 1,073,741,822 |
/3 | 224.0.0.0 | 536,870,910 |
/4 | 240.0.0.0 | 268,435,454 |
/5 | 248.0.0.0 | 134,217,726 |
/6 | 252.0.0.0 | 67,108,862 |
/7 | 254.0.0.0 | 33,554,430 |
Class A | ||
/8 | 255.0.0.0 | 16,777,214 |
/9 | 255.128.0.0 | 8,388,606 |
/10 | 255.192.0.0 | 4,194,302 |
/11 | 255.224.0.0 | 2,097,150 |
/12 | 255.240.0.0 | 1,048,574 |
/13 | 255.248.0.0 | 524,286 |
/14 | 255.252.0.0 | 262,142 |
/15 | 255.254.0.0 | 131,070 |
Class B | ||
/16 | 255.255.0.0 | 65,534 |
/17 | 255.255.128.0 | 32,766 |
/18 | 255.255.192.0 | 16,382 |
/19 | 255.255.224.0 | 8,190 |
/20 | 255.255.240.0 | 4,094 |
/21 | 255.255.248.0 | 2,046 |
/22 | 255.255.252.0 | 1,022 |
/23 | 255.255.254.0 | 510 |
Class C | ||
/24 | 255.255.255.0 | 254 |
/25 | 255.255.255.128 | 126 |
/26 | 255.255.255.192 | 62 |
/27 | 255.255.255.224 | 30 |
/28 | 255.255.255.240 | 14 |
/29 | 255.255.255.248 | 6 |
/30 | 255.255.255.252 | 2 |
/31 | 255.255.255.254 | 0 |
/32 | 255.255.255.255 | 0 |
- https://www.cyberciti.biz/faq/linux-ip-command-examples-usage-syntax/
- https://access.redhat.com/sites/default/files/attachments/rh_ip_command_cheatsheet_1214_jcs_print.pdf
- https://octetz.com/docs/2020/2020-11-13-vm-networks/
- Simple Concepts: CIDR Notation https://www.youtube.com/watch?v=u13AdjAUNmA
- https://www.calculator.net/ip-subnet-calculator.html