Advertisement: Linux VPS for $4/month - based on OpenVZ, credit card accepted, automatic setup.
+ Post New Thread
Results 1 to 2 of 2

Thread: How to set static IP on Linux with NetworkManager (most of the Linux distributions?)

  1. #1
    Fli
    Fli is offline
    Administrator Fli's Avatar
    Join Date
    Mar 2013
    Posts
    2,603

    How to set static IP on Linux with NetworkManager (most of the Linux distributions?)

    This is any attempt:

    A)
    in router configuration, DHCP LAN client list, you may be able to make it remember current IP so it always use it (until you reset the router).

    B)
    right click the network conenction icon in the Linux menu bar (NetworkManager), Edit connections, Edit your main conenction, go to IPv4 tab, switch from DHCP to manual and set your desired LAN IP (if router is 192.168.0.1, then maybe 192.168.0.15) mask is 24, gateway is router IP, DNS is router IP and then after coma add maybe 1.1.1.1 (cloudflare's open dns IP). Disable/enable this connection in NetworkManager (NM).

    C)
    1. If you do not know your router address and you are connected to it, IP can be listed by "ip r|grep default"
    2. Open current main network interface NetworkManager configuration file located in: /etc/NetworkManager/system-connections/:
    Following may work to do it:
    nic=$(ip -o -4 route show to default|head -n1|awk '{print $5}') && sudo nano /etc/NetworkManager/system-connections/"$nic".nmconnection||sudo vi /etc/NetworkManager/system-connections/"$nic".nmconnection
    3. in [ipv4] section replace that section lines, mybe just 1 line: "method=auto" by something like following (using your LAN 192.168.x.x IPs):
    address1=192.168.0.20/24,192.168.0.1
    dns=192.168.0.1;1.1.1.1;8.8.8.8;
    dns-search=
    method=manual
    4. run:
    nmcli network off;nmcli network on;nmcli;echo -e "\nWaiting 10 seconds for the network interface to come up to ping to internet";sleep 10;ping -c 2 -w 2 1.1.1.1
    if using VPN, restart it after done

  2. #2
    Junior Member johncena's Avatar
    Join Date
    Oct 2021
    Posts
    2


    Is this useful / helpfull? Yes | No
    Thanks for sharing this information..very useful content

+ Post New Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
 Protected by : ZB BLOCK  &  StopForumSpam