Linux命令_网络配置
Linux命令_网络配置
Linux网络配置方法简介
配置IP地址 (ip/ifconfig)
命令行方式(重启丢失)
# 使用ifconfig (interface config)
ifconfig eth0 192.168.1.3 netmask 255.255.255.0
# 使用用ip命令增加一个IP
ip addr add 192.168.1.4/24 dev eth0
# 使用ifconfig增加网卡别名
ifconfig eth0:0 192.168.1.10
修改配置文件方式(永久)
这样配置的 IP 地址重启机器后会丢失,所以一般应该把网络配置写入文件中。
- Ubuntu 和 Debain:可以将网卡配置写入
/etc/network/interfaces
- Redhat 和 CentOS:则需要写入
/etc/sysconfig/network-scripts/ifcfg-eth0
中
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.1
auto eth1
iface eth1 inet dhcp
配置默认路由 (ip/route)
# 使用route命令
route add default gw 192.168.1.1
# 也可以使用ip命令
ip route add default via 192.168.1.1
配置VLAN (vconfig)
# 安装并加载内核模块
apt-get install vlan
modprobe 8021q
# 添加vlan
vconfig add eth0 100
ifconfig eth0.100 192.168.100.2 netmask 255.255.255.0
# 删除vlan
vconfig rem eth0.100
配置硬件选项 (ethtool)
# 改变speed
ethtool -s eth0 speed 1000 duplex full
# 关闭GRO
ethtool -K eth0 gro off
# 开启网卡多队列
ethtool -L eth0 combined 4
# 开启vxlan offload
ethtool -K ens2f0 rx-checksum on
ethtool -K ens2f0 tx-udp_tnl-segmentation on
# 查询网卡统计
ethtool -S eth0
链接到当前文件 0
没有文件链接到当前文件