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

  • Look for interfaces like 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

  • This requests an IP from the router.
  • Verify the IP with: ip a

  • 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]

  • Change the IP (192.168.1.100), gateway (192.168.1.1), and DNS as needed.
  • Apply changes:

  • 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.conf

    Add:
    nameserver 8.8.8.8
    nameserver 1.1.1.1

  • 8.8.8.8 (Google DNS) and 1.1.1.1 (Cloudflare DNS).
  • This will reset on reboot unless set permanently in netplan.

  • Step 6: Test the Connection

    Ping a public website to verify connectivity:

    ping google.com

  • If you get replies, the network is working! 
  • If not, check IP, DNS, and gateway configurations.

  • Restart 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 IPs
    • sudo ip link set eth0 up – Enable interface
    • sudo dhclient eth0 – Get IP dynamically
    • sudo nano /etc/netplan/01-netcfg.yaml – Set static IP
    • sudo netplan apply – Apply network changes
    • ping google.com – Test connection

    Comments

    Popular posts from this blog

    IT Workshop GXESL208 KTU BTech 2024 Scheme - Dr Binu V P

    Familiarization of basic Linux Commands- ls, mkdir, rmdir , rm, cat, cp, mv , chmod