命令配置的都是临时地址,要永久生效还是要修改配置文件!
ifconfig eth0 192.168.0.22 netmask 255.255.255.0
#添加第一块网卡ip 与子网掩码
/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 设备名称
BOOTPROTO=dhcp # /static /none 自动获取、静态ip;静态ip时要指定ip、掩码和网关
IPADDR=192.168.1.2 #ip地址
NETMASK=255.255.255.0 #掩码
GATEWAY=192.168.1.1 #网关
ONBOOT=yes #开机激活网卡
service network restart
#重启网络
$sudo vi /etc/network/interfaces
iface eth0 inet dhcp ##自动获取ip
auto eth0
iface eth0 inet static #设置为静态
address 192.168.0.22
netmask 255.255.255.0
gateway 192.168.0.1
$ sudo /etc/init.d/networking restart
# 重启网络
redhat/centos网卡虚地址
cp ifcfg-eth0 ifcfg-eth0:1
配置文件设备名
DEVICE=eth0 改为eth0:1
Ubuntu 三线虚地址
iface em1 inet static
address 183.136.1.2
netmask 255.255.255.240
gateway 183.136.1.1
auto em1:1
iface em1:1 inet static
address 112.13.1.2
netmask 255.255.255.240
auto em1:2
iface em1:2 inet static
address 121.52.1.2
netmask 255.255.255.240
route del -net 0.0.0.0 netmask 0.0.0.0 gw 192.168.1.1
#删除默认路由
route add default gw 192.168.1.1 metric 1
#添加默认路由metric 默认为0
route add default gw 192.168.0.1 dev eth0
#添加缺省路由 gw =gateway 网关 dev eth0设备的第一个网卡
route add -net 192.168.1.0/24 gw 192.168.0.1
#添加192.168.1段静态路由走192.168.0.1
route del -net 192.168.2.0 netmask 255.255.255.0
#删除去192.168.2网段的路由
route del -net 192.168.12.0 netmask 255.255.252.0 gw 192.168.8.1
#删除去192.168.12.0网段出口192.68.8.1的路由
route -n
#查看路由表条目
/etc/sysconfig/network
route add default gw 10.0.0.1 metric 99
#网卡上网关metric优先级为100,添加优先路由出口10.0.0.1
vi /etc/resolv.conf
nameserver 223.5.5.5
nameserver 8.8.8.8
#最多能添加3个
hostname xxxx #临时命令
cat /etc/hostname
aliyun-web-1-1
cat /etc/sysconfig/network
hostname xxxx #临时命令
vi /etc/hosts
127.0.0.1 to-share.net # hosts 绑定域名