1. 程式人生 > >Ubuntu配置和修改IP地址

Ubuntu配置和修改IP地址

ren from var address can gen pen -name get

http://blog.csdn.net/readiay/article/details/50866709

Ubuntu配置和修改IP地址


1、修改配置文件/etc/network/interfaces
[email protected]:~# sudo gedit /etc/network/interfaces


添加以下內容:
auto eth0 #設置自動啟動eth0接口
iface eth0 inet static #配置靜態IP
address 192.168.11.88 #IP地址
netmask 255.255.255.0 #子網掩碼
gateway 192.168.11.1 #默認網關


2、修改DNS
sudo gedit /etc/resolve.conf
nameserver 8.8.8.8 #當地dns服務器(用ipconfig /all 查看本地dns,第一個dns是默認的,共有2個dns)


在這裏修改的dns重啟電腦後就消失了,要想永久有效需要進行下面的配置:


sudo vi /etc/resolvconf/resolv.conf.d/base

在打開的文件中添加

nameserver 202.103.224.68
nameserver 202.103.225.68



註:#後面的註釋信息不要加進去。


3、重啟網絡,使配置生效
sudo /etc/init.d/networking restart


4、查看ip是否配置成功 [email protected]:~# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0c:29:2d:89:40
inet addr:192.168.11.88 Bcast:192.168.11.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe2d:8940/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:223 errors:0 dropped:0 overruns:0 frame:0
TX packets:253 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:24219 (24.2 KB) TX bytes:22960 (22.9 KB)
Interrupt:19 Base address:0×2024


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:16436 Metric:1
RX packets:48 errors:0 dropped:0 overruns:0 frame:0
TX packets:48 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3964 (3.9 KB) TX bytes:3964 (3.9 KB)


[email protected]

/* */:~#


註:紅字加粗“192.168.11.88”跟上面配置的ip一樣,表示ip配置成功。

You Are Here: Home → Linux → How To‘s → Ubuntu Change default network name (ens33) to old “eth0” on Ubuntu 16.04

Change default network name (ens33) to old “eth0” on Ubuntu 16.04

技術分享Change default network name (ens33) to old “eth0” on Ubuntu 16.04

Just after the Ubuntu 16.04 installation, I came to know that the network interface name got changed to ens33 from old school eth0. If you ever interested in changing interface names to old type ethX, here is the tutorial for you.

As you can see in the following command, my system is having a network adapter called ens33.

Note: This is just the case of VMware environment, it may vary depends on the hardware but the steps to get back ethX will be the same.

$ ip a

1: lo: <loopback,up,lower_up> 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: ens33: <broadcast,multicast,up,lower_up> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:05:a3:e2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.12.12/24 brd 192.168.12.255 scope global dynamic ens33
       valid_lft 1683sec preferred_lft 1683sec
    inet6 fe80::20c:29ff:fe05:a3e2/64 scope link
       valid_lft forever preferred_lft forever

From the dmesg command, you can see that the device got renamed during the system boot.

$ dmesg | grep -i eth

[    3.050064] e1000 0000:02:01.0 eth0: (PCI:66MHz:32-bit) 00:0c:29:05:a3:e2
[    3.050074] e1000 0000:02:01.0 eth0: Intel(R) PRO/1000 Network Connection
[    3.057410] e1000 0000:02:01.0 ens33: renamed from eth0

To get an ethX back, edit the grub file.

$ sudo nano /etc/default/grub

Look for “GRUB_CMDLINE_LINUX” and add the following”net.ifnames=0 biosdevname=0“.

From:

GRUB_CMDLINE_LINUX=""

To:

GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"

Generate a new grub file using the following command.

$ sudo grub-mkconfig -o /boot/grub/grub.cfg

Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.4.0-15-generic
Found initrd image: /boot/initrd.img-4.4.0-15-generic
Found memtest86+ image: /memtest86+.elf
Found memtest86+ image: /memtest86+.bin
done

Edit the interface file and change the network device name so that you will have a static ip address for ethX.

If your network card is DHCP enabled, you can skip the below step

$ sudo nano /etc/network/interfaces

From:

auto ens33
iface ens33 inet static
           address 192.168.12.12
           netmask 255.255.255.0
           dns-nameservers 192.168.12.2
           gateway 192.168.12.2

To:

auto eth0
iface eth0 inet static
           address 192.168.12.12
           netmask 255.255.255.0
           dns-nameservers 192.168.12.2
           gateway 192.168.12.2

Reboot your system.

$ sudo reboot

After the system reboot, just check whether you have an ethX back.

$ ip a
1: lo: <loopback,up,lower_up> 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: eth0: <broadcast,multicast,up,lower_up> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:05:a3:e2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.12.12/24 brd 192.168.12.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe05:a3e2/64 scope link
       valid_lft forever preferred_lft forever

That’s All, drop your thoughts in the comments section.

Ubuntu配置和修改IP地址