This is how a network needs to be configured when spinning up a linux server. For example for a fresh install of a local lab on of linux virtual machines on VMware Fusion, Virtualbox or AWS, etc. These are some of the technical details that need to be verified and configured properly.
- Host Address: The unique IP address of your system on the network.
- Network Subnet Address: Defines the local network's range.
- Default Router/Gateway: The device that routes traffic to other networks.
- System Host Name: The name by which a system is identified on a network.
- DNS Server Address: Used for resolving hostnames to IP addresses.
Network Configuration Files:
- Linux systems use
systemd-networkd
service for network interface detection and configuration. - Different distributions have different files for network settings, such as:
-
Debian-based:
/etc/network/interfaces
-
Red Hat-based:
/etc/sysconfig/network-scripts
directory -
OpenSUSE:
/etc/sysconfig/network
-
Debian-based:
Configuration Methods:
- Manual Editing: Directly modify network configuration files.
- Graphical Tools: Use distribution-provided GUI tools.
- Command-Line Tools: Utilize terminal commands for configuration.
Examples:
File Configuration
For CentOs file /etc/sysconfig/network-scripts/ifcfg- (such as eth0 or enp3s0)
DEVICE=<interface_name>
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
Command Line
There are multiple types of commands, most common are ifconfig
, ip
, nmcli
.
- ifconfig: it's legacy but commonly known.
- nmcli: for simple network configurations.
- ip: for advanced configurations, which could involve scripting and more complex scenarios.
ip command example:
# Set IP
>> ip addr add 192.168.1.100/24 dev <interface_name>
# Activate the interface device
>> ip link set <interface_name> up
# Set Default router
>> ip route add default via 192.168.1.1
# Set DNS (not included in ip commands, gotta write directly to file)
>> echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
>> echo "nameserver 8.8.4.4" | sudo tee -a /etc/resolv.conf
# ONBOOT=yes has to be set manually as well
nmcli command example
nmcli con mod "ConnectionName" ipv4.addresses 192.168.1.100/24
nmcli con mod "ConnectionName" ipv4.gateway 192.168.1.1
nmcli con mod "ConnectionName" ipv4.dns "8.8.8.8,8.8.4.4"
nmcli con mod "ConnectionName" ipv4.method manual
nmcli con mod "ConnectionName" connection.autoconnect yes
Top comments (0)