Centos7 配置固定IP与关闭防火墙
博客专区 > 诺岚 的博客 > 博客详情
Centos7 配置固定IP与关闭防火墙
诺岚 发表于5个月前
Centos7 配置固定IP与关闭防火墙
  • 发表于 5个月前
  • 阅读 13
  • 收藏 0
  • 点赞 0
  • 评论 0

标题:腾讯云 新注册用户域名抢购1元起>>>   

实验版本:


@查看系统版本
[root@localhost ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core) 
@查看内核版本
[root@localhost ~]# cat /proc/version
Linux version 3.10.0-327.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) ) #1 SMP Thu Nov 19 22:10:57 UTC 2015
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux 

1.查看本地IP

@为注释,请不要复制到命令行中

[root@localhost ~]# ip addr  @查看本地IP
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:87:bd:d8 brd ff:ff:ff:ff:ff:ff
    inet 10.2.202.142/24 brd 10.2.202.255 scope global dynamic eno16777736
       valid_lft 1295898sec preferred_lft 1295898sec
    inet6 fe80::20c:29ff:fe87:bdd8/64 scope link 
       valid_lft forever preferred_lft forever
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eno16777736
@按I进入编辑模式,修改IP信息,修改后按Esc退出,再软件:wq 保存退出
@修改前:-------------
BOOTPROTO="dhcp"
DEFROUTE="yes"
PEERDNS="yes"
PEERROUTES="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"
IPV6_FAILURE_FATAL="no"
NAME="eno16777736"
UUID="2c39bd3a-7554-4fea-bc9c-5442be7e17eb"
DEVICE="eno16777736"
ONBOOT="yes"
@修后后:---------------
TYPE="Ethernet"
BOOTPROTO="static"
DEFROUTE="yes"
PEERDNS="yes"
PEERROUTES="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"
IPV6_FAILURE_FATAL="no"
NAME="eno16777736"
UUID="2c39bd3a-7554-4fea-bc9c-5442be7e17eb"
DEVICE="eno16777736"
ONBOOT="yes" #开机启用本配置  
IPADDR=10.2.202.38 #静态IP  
GATEWAY=10.2.202.254 #默认网关  
NETMASK=255.255.255.0 #子网掩码  
DNS1=202.96.128.166 #DNS 配置 
@重启网络服务
[root@localhost ~]# systemctl restart network.service

@关闭访火墙

@关闭防火墙
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@localhost ~]# firewall-cmd --state @查看防火墙状态
not running

先查询本机是否安装java环境,删除原有的java,以免冲突

[root@localhost ~]# rpm -qa | grep java
python-javapackages-3.4.1-11.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64
tzdata-java-2015g-1.el7.noarch
java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64
java-1.7.0-openjdk-1.7.0.91-2.6.2.3.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.3.el7.x86_64
javapackages-tools-3.4.1-11.el7.noarch

#卸载OpenJDK,执行以下操作:

[root@localhost ~]# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64
[root@localhost ~]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.91-2.6.2.3.el7.x86_64
[root@localhost ~]# rpm -e --nodeps tzdata-java-2015g-1.el7.noarch
[root@localhost ~]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64
[root@localhost ~]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.3.el7.x86_64
[root@localhost ~]# rpm -e --nodeps javapackages-tools-3.4.1-11.el7.noarch
[root@localhost ~]# rpm -e --nodeps python-javapackages-3.4.1-11.el7.noarch


安装JDK。在官网下载:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
#Linux x64    176.92 MB      jdk-8u144-linux-x64.tar.gz
#安装JDK 
# mkdir -p /usr/local/java
# cd /usr/local/java

[root@localhost ~]# mkdir -p /usr/local/java
[root@localhost ~]# cd /usr/local/java/
[root@localhost java]# 
#上传JDK 到此目录,并解压
# tar -xvzf jdk-8u144-linux-x64.tar.gz
[root@localhost ~]# tar -xvzf jdk-8u144-linux-x64.tar.gz
### 设置新的 JDK 为默认 JDK.
vim /etc/profile

向文件里面追加以下内容:

JAVA_HOME=/usr/local/java/jdk1.8.0_144/
JRE_HOME=/usr/local/java/jdk1.8.0_144/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH


使修改生效
[root@localhost ~]# source /etc/profile   //使修改立即生效
[root@localhost ~]#     echo $PATH   //查看PATH值

# echo "export JAVA_HOME=/usr/local/java/jdk1.8.0_144/" >> /etc/profile
# echo "export PATH=$PATH:$JAVA_HOME/bin" >> /etc/profile
# source /etc/profile
[root@localhost java]# echo "export JAVA_HOME=/usr/local/java/jdk1.8.0_144/" >> /etc/profile
[root@localhost java]# echo "export PATH=$PATH:$JAVA_HOME/bin" >> /etc/profile
[root@localhost java]# source /etc/profile
#测试运行 看是否配置成功
# $JAVA_HOME/bin/java -version
[root@localhost java]# $JAVA_HOME/bin/java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
 

共有 人打赏支持
粉丝 0
博文 63
码字总数 102814
×
诺岚
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: