Setting up a computer in LAN
Understand the Basics
A LAN connects devices in a small area for resource sharing and communication. On a Linux system, you configure the LAN by setting up:
- Network Interfaces: Ethernet (wired) or Wi-Fi (wireless).
- IP Addressing: Dynamic (via DHCP) or Static (manual assignment).
- Sharing Resources: Using protocols like Samba or NFS for file sharing and CUPS for printers.
Goal:
- Enable a network interface
- Get an IP address (Dynamic or Static)
- Configure DNS
- Test the network
Step 1: Check Network Interfaces
To list all available network interfaces:
ip a or
ifconfig
eth0
, enp3s0
(Ethernet), or wlan0
(Wi-Fi).lo
is the loopback interface (internal to the machine).Step 2: Enable the Network Interface
If the interface is down, bring it up:
sudo ip link set eth0 up
or
sudo ifconfig eth0 up
Replace
eth0
with your interface name (e.g., enp3s0
or wlan0
).Step 3: Get Dynamic IP Address (via DHCP)
To automatically get an IP from a DHCP server:
sudo dhclient eth0
Step 4: Assign a Static IP Address (Optional)
If you want to manually set an IP address:
sudo nano /etc/netplan/01-netcfg.yaml
Add the following (for Ethernet
eth0
):network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
192.168.1.100
), gateway (192.168.1.1
), and DNS as needed.sudo netplan apply
Optional: Set Static IP (Simple Method)
Edit the network configuration file directly:
sudo nano /etc/network/interfaces
Add the following (for static IP on
eth0
):auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 1.1.1.1
Step 5: Configure DNS (Temporary)
To temporarily set DNS servers:
sudo nano /etc/resolv.confAdd:
nameserver 8.8.8.8
nameserver 1.1.1.1
8.8.8.8
(Google DNS) and 1.1.1.1
(Cloudflare DNS).Step 6: Test the Connection
Ping a public website to verify connectivity:
ping google.comRestart Networking Service
If changes don’t apply immediately:
sudo systemctl restart networking
or
sudo service networking restart
Quick Recap of Commands:
ip a
– Check interfaces and IPssudo ip link set eth0 up
– Enable interfacesudo dhclient eth0
– Get IP dynamicallysudo nano /etc/netplan/01-netcfg.yaml
– Set static IPsudo netplan apply
– Apply network changesping google.com
– Test connection
Comments
Post a Comment