set a static IP in Ubuntu 16 or above

Linux static ip in Ubuntu 45 times1 answer1 follower
0
Mel Khamlichi 103 Rep. Avishek Kumar edited question

I  installed   Ubuntu 16.10  How to set a static IP address .  and  if possible how to do this with ipv4 and  ipv6

♥ Spread the love ♥
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
0
Avishek Kumar 449 Rep. Admin edited answer

To add a static IP in Ubuntu(and other debian derivatives), edit /etc/network/interfaces

sudo nano -c /etc/network/interfaces

Add the below content to the end of the file. You need to change name of interface and values in address, network, broadcast, netmask, gateway and dns-nameservers

auto enp0s3
iface enp0s3 inet static
address 10.0.2.16
network 10.0.2.0
broadcast 10.0.2.255
netmask 255.255.252.0
gateway 10.0.2.2
dns-nameservers 8.8.8.8 192.168.1.1

Restart Networking

sudo /etc/init.d/networking restart

Here enp0s3 is the name of my wired network interface. You may get the details of your network card by running

  1. # ifconfig
  2. enp0s3    Link encap:Ethernet  HWaddr 08:00:27:82:25:a4  
    inet addr:10.0.2.16  Bcast:10.0.2.255  Mask:255.255.255.0
    inet6 addr: fe80::a00:27ff:fe82:25a4/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
    RX packets:22 errors:0 dropped:0 overruns:0 frame:0
    TX packets:101 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000 
    RX bytes:1913 (1.9 KB)  TX bytes:11456 (11.4 KB)
    lo        Link encap:Local Loopback  
    inet addr:127.0.0.1  Mask:255.0.0.0
    inet6 addr: ::1/128 Scope:Host
    UP LOOPBACK RUNNING  MTU:65536  Metric:1
    RX packets:165 errors:0 dropped:0 overruns:0 frame:0
    TX packets:165 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1 
    RX bytes:12129 (12.1 KB)  TX bytes:12129 (12.1 KB)
    
  3. $ ip addr show
  4. 1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
    valid_lft forever preferred_lft forever
    2: enp0s3:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:82:25:a4 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.16/24 brd 10.0.2.255 scope global enp0s3
    valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe82:25a4/64 scope link 
    valid_lft forever preferred_lft forever
    
  5. $ ip link show
  6. 1: lo:  mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    2: enp0s3:  mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:82:25:a4 brd ff:ff:ff:ff:ff:ff
    
  7. $ netstat -i
  8. Kernel Interface table
    Iface   MTU Met   RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
    enp0s3     1500 0      1096      0      0 0          1010      0      0      0 BMRU
    lo        65536 0       165      0      0 0           165      0      0      0 LRU
    
♥ Spread the love ♥
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
×

Login