Show List

Network configuration in Linux

Network configuration in Linux involves setting up network interfaces, IP addresses, and other networking parameters. Here are some code examples for common network configuration tasks in Linux:

  • Listing network interfaces

To list the available network interfaces in Linux, use the ip command followed by the link subcommand. Here's an example:

bash
Copy code
ip link show

This command will display information about each network interface, including its name, MAC address, and state.

  • Configuring network interfaces

To configure a network interface in Linux, use the ip command followed by the address subcommand. Here are some examples:

  • Assign a static IP address to an interface:

csharp
Copy code
sudo ip address add 192.168.1.100/24 dev eth0
  • Bring an interface up or down:

  • bash
    Copy code
    sudo ip link set eth0 up sudo ip link set eth0 down
    • Setting up network routes

    To set up network routes in Linux, use the ip command followed by the route subcommand. Here are some examples:

    • Add a new route:

    csharp
    Copy code
    sudo ip route add 10.0.0.0/24 via 192.168.1.1
  • Remove an existing route:

  • python
    Copy code
    sudo ip route del 10.0.0.0/24
    • Configuring DNS

    To configure DNS in Linux, edit the /etc/resolv.conf file and add the desired DNS server IP addresses. Here's an example:

    bash
    Copy code
    sudo nano /etc/resolv.conf # Add the following lines: nameserver 8.8.8.8 nameserver 8.8.4.4

    These lines will configure the system to use the Google DNS servers.

    • Checking network connectivity

    To check network connectivity in Linux, use the ping command followed by the IP address or hostname of the target system. Here's an example:

    Copy code
    ping google.com

    This command will send ICMP packets to the Google server and report any errors or response times.

    These are some examples of basic network configuration tasks in Linux. There are many more advanced options available, such as configuring network bridges and VLANs, but these commands should be enough to get you started.


        Leave a Comment


    • captcha text