linux下配置IP

1. 相关文件

# cd /etc/network/
# vi interfaces
(以下为文件内容)
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 1.1.15.15
netmask 255.255.255.0
network 0.0.0.0
gateway 1.1.15.1

也可用相关命令:

ifconfig eth0 x.x.x.x netmask x.x.x.x
如:ifconfig eth0 1.1.1.1 netmask 255.255.0.0

2. 配置虚拟IP地址

相关命令:

ifconfig eth1:0  x.x.x.x netmask 255.255.0.0
如:ifconfig eth0:0 2.1.1.1 netmask 255.255.0.0

子网卡并不是实际上的网络接口设备,但可以作为网络接口在设备中出现。其必须依赖于物理网卡

3. 配置DNS

相关文件

# vi  /etc/resolv.conf
(以下为文件内容)
# Generated by NetworkManager
# search localdomain
# nameserver 192.168.23.2
nameserver 114.114.114.114
nameserver 8.8.8.8

修改相应的nameserver内容即可。

若不通,则可继续修改如下文件:

# vi /etc/nsswitch.conf
(以下为相关内容)
# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

passwd: compat
group: compat
shadow: compat
gshadow: files

# hosts: files mdns4_minimal [NOTFOUND=return] dns myhostname
hosts: files dns wins
networks: files

protocols: db files
services: db files
ethers: db files
rpc: db files

netgroup: nis

修改相应的hosts部分,添加dns wins即可