This article describes how to set a static IP address in ubuntu13.04. For more information, see Ubuntu.
Operating system: Ubuntu13.04
Set static IP address:
Preparation:
1. view the network card, IP address, and subnet mask netmask in use. my name is eth0.
Copy codeThe code is as follows:
Ifconfig
Eth0 Link encap: Ethernet HWaddr ec: 9a: 74: 36: c8: 8c
Inet addr: 192.168.1.100 Bcast: 192.168.1.255 Mask: 255.255.255.0
# IP: 192.168.1.100, netmask: 255.255.255.0
2. View gateway
Copy codeThe code is as follows:
Route-n
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
# Gateway: 192.168.1.1
# Dns: 192.168.1.1 # generally, it works with Gateways. of course, you can also set other dns
3. set static IP now
Copy codeThe code is as follows:
Sudo vim/etc/network/interfaces
# Interfaces (5) file used by ifup (8) and ifdown (8)
Auto lo
Iface lo inet loopback
# Set Static IP
Auto eth0 # My network card
Iface eth0 inet static # static, relative to dynamic (dhcp, that is, iface eth0 inet dhcp)
Address 192.168.1.100 # you can set available ip addresses in the same network segment, for example, 192.168.1.102
Gateway 192.168.1.1 # gateway
Netmask 255.255.255.0 # subnet mask
Dns-nameservers 192.168.1.1 # you can set multiple dns addresses or do not set them here. edit/etc/resolv. conf
Dns-nameservers 114.114.114.114
4. restart the NIC
Copy codeThe code is as follows:
Sudo service networking restart
# Or sudo/etc/init. d/networking restart
# If the problem persists, restart reboot.
# Note:
# When dns-nameservers is not set, manually add it in/etc/resolv. conf
Sudo vim/etc/resolv. cof
Nameserver 192.168.1.1
In addition:
In earlier versions, you need to set resolv under/etc. conf file, and add nameserver to connect to the internet. Otherwise, you can only access it through ip addresses and cannot parse the URL. (nslookup can view the ip address of the website. of course, you must first have dns ).
This method is no longer recommended after Ubuntu12.04, because no matter what value you want to set in the configuration file, it will be restored to the initial state after restart. (Of course, it does not include the automatic setting of the boot script)
We recommend that you directly add dns-nameservers to the interfaces configuration file. <网关ip> This line.