Linux網絡配置 -- ubuntu

第一種命令行配置

配置eth0IP地址, 同時激活該設備

#ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up

配置eth0別名設備eth0:1IP地址,並添加路由

#ifconfig eth0 192.168.1.3

#route add host 192.168.1.3 d

第二種 修改相關文件
編輯/etc/network/interface文件如下
先添加
auto lo
iface lo inet loopback
auto eth0
如果是自動獲取ip,添加
iface eth0 inet dhcp
如果是手動配置ip,添加
iface eth0 inet static
address xxx.xxx.xxx.xxx
netmask xxx.xxx.xxx.xxx
network xxx.xxx.xxx.xxx
boardcast xxx.xxx.xxx.xxx
gateway xxx.xxx.xxx.xxx

Ubuntu網絡配置相關命令:

1ifconfig

配置eth0IP地址, 同時激活該設備
#ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up

配置eth0別名設備eth0:1IP地址,並添加路由
#ifconfig eth0 192.168.1.3
#route add
host 192.168.1.3 dev eth0:1

激活設備
#ifconfig eth0 up

禁用設備
#ifconfig eth0 down

查看指定的網絡接口的配置
#ifconfig eth0

查看所有的網絡接口配置
#ifconfig

2 route
可以使用route命令來配置並查看內核路由表的配置情況,例如: 

添加到主機的路由
#route add
host 192.168.1.2 dev eth0:0
#route add
host 10.20.30.148 gw 10.20.30.40

添加到網絡的路由
#route add
net 10.20.30.40 netmask 255.255.255.248eth0
#route add
net 10.20.30.48 netmask 255.255.255.248 gw10.20.30.41
#route add
net 192.168.1.0/24 eth1

添加默認網關
#route add default gw 192.168.1.1

查看內核路由表的配置
#route

刪除路由
#route del
host 192.168.1.2 dev eth0:0
#route del
host 10.20.30.148 gw 10.20.30.40
#route del
net 10.20.30.40 netmask 255.255.255.248eth0
#route del
net 10.20.30.48 netmask 255.255.255.248 gw10.20.30.41
#route del
net 192.168.1.0/24 eth1
#route del default gw 192.168.1.1
對於12兩點可使用下面的語句實現:
ifconfig eth0 172.16.19.71 netmask 255.255.255.0
route 0.0.0.0 gw 172.16.19.254
service network restart

3 traceroute
可以使用traceroute命令顯示數據包到達目的主機所經過的路由,例如:
#traceroute x

4 ping 
可以使用ping 命令來測試網絡的連通性,例如:
#ping x
#ping
c 4 192.168.1.12

5 netstat
可以使用netstat命令來顯示網絡狀態信息,例如:

顯示網絡接口狀態信息
#netstat
i

顯示所有監控中的服務器的Socket和正使用Socket的程序信息
#netstat
lpe

顯示內核路由表信息
#netstat
r
#netstat
nr

顯示TCP/UDP傳輸協議的連接狀態
#netstat
t
#netstat
u

6 hostname
可以使用hostname命令來更改主機名,例如;
#hostname myhost

7 arp
可以使用arp命令來配置並查看arp緩存,例如:

查看arp緩存
#arp

添加一個IP地址和MAC地址的對應記錄
#arp
s 192.168.33.15 00:60:08:27:CE:B2

刪除一個IP地址和MAC地址的對應緩存記錄
#arp
d192.168.33.15



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章