From:http://blog.csdn.net/ithomer/article/details/6264881

以eth0为例

 

1. 以DHCP方式配置网卡

编辑文件: /etc/network/interfaces:

sudo vi /etc/network/interfaces

并用下面的行来替换有关eth0的行:

# The primary network interface, 
# use DHCP to find our address
auto eth0
iface eth0 inet dhcp

用下面的命令使网络设置生效:

sudo /etc/init.d/networking restart

当然,也可以在命令行下直接输入下面的命令来获取地址

sudo dhclient eth0

 


2. 为网卡配置静态IP地址

编辑文件: /etc/network/interfaces:

sudo vi /etc/network/interfaces

并用下面的行来替换有关eth0的行:

# The primary network interface, 
# use Static to find our address
auto eth0
iface eth0 inet static
address 192.168.1.98            
gateway 192.168.1.1             
netmask 255.255.255.0           
network 192.168.1.0
broadcast 192.168.1.255

用下面的命令使网络设置生效:

sudo /etc/init.d/networking restart

注: 生效后,需要配置DNS后才可上网(步骤5)

3. 设定第二个IP地址(虚拟IP地址)

编辑文件/etc/network/interfaces:

sudo vi /etc/network/interfaces

在该文件中添加如下的行:

auto eth0:1
iface eth0:1 inet static
address 192.168.1.60
netmask 255.255.255.0
network x.x.x.x
broadcast x.x.x.x
gateway x.x.x.x

根据你的情况填上所有诸如address,netmask,network,broadcast和gateways等信息.

用下面的命令使网络设置生效:

sudo /etc/init.d/networking restart

 

4. 设置主机名称(hostname)

使用下面的命令来查看当前主机的主机名称:

sudo /bin/hostname

使用下面的命令来设置当前主机的主机名称:

sudo /bin/hostname newname

系统启动时,它会从/etc/hostname来读取主机的名称.

关于设置主机名称的更多信息,请访问这里

5. 配置DNS

首先,你可以在/etc/hosts中加入一些主机名称和这些主机名称对应的IP地址

要访问DNS 服务器来进行查询,需要设置/etc/resolv.conf文件.

例如: 假设DNS服务器的IP地址是192.168.1.1

编辑文件: /etc/hosts

sudo vi /etc/hosts

编辑内容如下:

nameserver 192.168.1.1

或者,编辑/etc/resolv.conf,添加内容如下:

sudo  vi  /etc/resolv.conf

用下面的命令使网络设置生效:

sudo /etc/init.d/networking restart

Ubuntu 关闭防火墙

root@ubuntu:/home/homer# ufw status            // 查看状态
Status: inactive
root@ubuntu:/home/homer# ufw enable          // 打开防火墙
Firewall is active and enabled on system startup
root@ubuntu:/home/homer# ufw status
Status: active
root@ubuntu:/home/homer# ufw disable          // 关闭防火墙
Firewall stopped and disabled on system startup
root@ubuntu:/home/homer# ufw status
Status: inactive

1、关闭ubuntu的防火墙 
      ufw disable
2、卸载了iptables
       apt-get remove iptables
3、关闭ubuntu中的防火墙的其余命令
        iptables -P INPUT ACCEPT
        iptables -P FORWARD ACCEPT
        iptables -P OUTPUT ACCEPT
        iptables -F

CentOS 关闭防火墙

/etc/init.d/iptables stop

[root@homeros logs]# /etc/init.d/iptables status       // 查看防火墙状态
iptables: Firewall is not running.
[root@homeros logs]# /etc/init.d/iptables start          // 开启防火墙
iptables: Applying firewall rules:                         [  OK  ]
[root@homeros logs]# /etc/init.d/iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
5    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 
Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination

[root@homeros logs]# /etc/init.d/iptables stop          // 关闭防火墙
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[root@homeros logs]# /etc/init.d/iptables status
iptables: Firewall is not running.

推荐参考:

英文原文:http://www.ubuntugeek.com/ubuntu-networking-configuration-using-command-line.html

centos 永久关闭防火墙方法

Ubuntu配置网络命令(转载)的更多相关文章

  1. Ubuntu配置网络遇到的一些问题

    Ubuntu配置网络遇到的一些问题 在配置Ubuntu网络时,曾遇到了一些问题.查找了一些博客,所幸都解决了.记录一下,以便日后查阅. 设置DNS sudo vim /etc/resolv.conf ...

  2. Ubuntu 配置Tomcat环境(转载)

    Ubuntu 配置Tomcat环境   1.下载Tomcat http://tomcat.apache.org/,下载Tomcat 8(由于目前最新eclipse不支持tomcat 9) 将下载的ap ...

  3. ubuntu配置网络和静态路由(界面配置形式)

    目录 网卡配置 静态ip配置 静态路由 外网ip配置(动态获取DHCP) 内网ip和静态路由配置 本文主要针对ubuntu18.0系统进行界面形式配置网络.并配置静态路由. 网卡配置 静态ip配置 打 ...

  4. 转: ubuntu配置NFS,挂载开发板

    ====================================== 命令: 1. $sudo apt-get install nfs-kernel-server           (安装N ...

  5. Ubuntu中网络配置interfaces与界面网络配置NetworkManager

    [Server版本] 在Ubuntu Server版本中,因为只存有命令行模式,所以要想进行网络参数设置,只能通过修改 /etc/network/interfaces .具体设置方法如下: (1) U ...

  6. centos和ubuntu的网络属性配置

        一. centos的网络配置    1.  修改 /etc/sysconfig/network-scripts/ifcfg-IFACE:             DEVICE:此配置文件应用到 ...

  7. ubuntu server 网络配置,主机名配置

    一.通过命令ifconfig -a 查看可用网络设备 通过上面的命令,本机可用的网络设备为enp4s0f0 和enp4s0f1 ,不同的系统版本和硬件配置网络设备名可能不一样,所以一定要先确认本机可用 ...

  8. ubuntu server 1604 配置网络信息

    对于新安装的linux 服务器(ubuntu server 1604)   一,配置网络 连接网线与路由器 查看系统的网卡信息 ifconfig -a //列出所有的网卡信息,不管启用还是没有启用的 ...

  9. 转载_虚拟机下LInux(终端)配置网络的方法

    出自: http://www.360doc.com/content/14/1027/11/17496895_420258403.shtml 对文章的重点进行剪贴,方便查看. 这几天在虚拟机vmware ...

随机推荐

  1. Machine Learning and Data Science 教授大师

    http://www.cs.cmu.edu/~avrim/courses.html Foundations of Data Science Avrim Blum, www.cs.cornell.edu ...

  2. log tree(merge)

    http://www-users.cs.umn.edu/~he/diff/p256-severance.pdf http://www.eecs.harvard.edu/~margo/cs165/pap ...

  3. 如何在Windows 下安装Python

    1.  安装源程序的选择 官网:https://www.python.org/downloads/ 选择版本下载,根据实际计算机位数(64位),下载的为: Python-2.7.10.amd64.ms ...

  4. 解决国内无法下载SDK问题——安卓镜像服务器列表

    mirrors.opencas.cn 80  稍快ubuntu.buct.cn    80 快 Android SDK在线更新镜像服务器 大连东软信息学院镜像服务器地址: http://mirrors ...

  5. java从零到变身爬虫大神(一)

    学习java3天有余,知道一些基本语法后 学习java爬虫,1天后开始出现明显效果 刚开始先从最简单的爬虫逻辑入手 爬虫最简单的解析面真的是这样 import org.jsoup.Jsoup; imp ...

  6. Android拍照、录像、录音代码范例

    <p>import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; import andro ...

  7. java中的包装类与装箱拆箱定义

    JAVA 中int类型转String类型的通常方法,有三种:  1.String.valueOf(int i)  2.Integer.toString(int i)  3.i+"" ...

  8. Linux启动过程详解 (转)

    启动第一步--加载BIOS当你打开计算机电源,计算机会首先加载BIOS信息,BIOS信息是如此的重要,以至于计算机必须在最开始就找到它.这是因为BIOS中包含了CPU的相关信息.设备启动顺序信息.硬盘 ...

  9. NAT,网络地址转换详解

    这个技术,是一个非常成熟的技术了,但是,为了将其弄得清楚点,体系点,也为了备忘,还是有必要在这里梳理一下! NAT:Network Address Translation. 这个主要是用在网络地址(I ...

  10. SVN-钩子祥解

    钩子脚本的具体写法就是操作系统中shell脚本程序的写法,请根据自己SVN所在的操作系统和shell程序进行相应的写作 所谓钩子就是与一些版本库事件触发的程序,例如新修订版本的创建,或是未版本化属性的 ...