linux network configuration - ghdrako/doc_snipets GitHub Wiki
Configuration example
CentOS server with 3 network interfaces: server1's ens33 network interface is going to be an external network interface, while network interfaces ens37, ens38, and ens39 are going to be internal network interfaces.
The company that we're discussing has multiple network subnets:
- 192.168.1.0/24 – This one is used for all of the server machines; we'll call this connection profile network1 when we configure it via nmcli.
- 192.168.2.0/24 – This one is used for all of the client machines; we'll call this connection profile network2 when we configure it via nmcli.
- 192.168.3.0/24 – This one is used for company wireless; we'll call this connection profile network3 when we configure it via nmcli
The First tree is using as internal conection.
The fourth network interface of our machine is going to act as our internet connection.
- Configure interface to forward to router
echo "1" > /proc/sys/net/ipv4/ip_forward
nmcli connection add con-name network1 ifname ens37 type ethernet ip4 192.168.1.254/24
nmcli connection add con-name network2 ifname ens38 type ethernet ip4 192.168.2.254/24
nmcli connection add con-name network3 ifname ens39 type ethernet ip4 192.168.3.254/24
- Check config -
nmcli con show
ip route show
our external network on ens33 – and in our virtual machine, it's using the 192.168.159.0/24 network
- allow internet access for these three subnets by adding these interfaces to the public zone.
nmcli connection modify ens33 connection.zone public
nmcli connection modify network1 connection.zone public
nmcli connection modify network2 connection.zone public
nmcli connection modify network3 connection.zone public
firewall-cmd --zone=public --add-masquerade --permanent
firewall-cmd --reload
firewall-cmd --list-all
- configure client1
ls /etc/netplan/
vi /etc/netplan/00-installer-config.yaml.
sudo netplan try
sudo netplan apply
sudo netplan –d apply # w przypadku bledow mozna debugowac
sudo systemctl restart network-manager
sudo systemctl restart system-networkd
- test if internet access from this machine works
- configure client2 Our CentOS virtual machine called client2 has a network interface called ens39. Let's set it up so that it's a part of the network2 subnet (we defined that subnet on server1). Let's say client2 is going to temporarily use 192.168.2.2/24 as its IP address:
nmcli connection add con-name network2 ifname ens39 type
ethernet ipv4.address 192.168.2.2/24 gateway 192.168.2.254
ipv4.dns 8.8.8.8,8.8.4.4
nmcli con reload network
- Check client2