1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Linux(CentOS/Ubuntu/Kali)のIPアドレスを固定する

Posted at

頻繁に設定するのでメモ程度に書いておく

環境 CentOS7 Ubuntu20.04 KaliLinux(VirtualBoxでネットワーク設定をブリッジアダプターに設定している)

IP,NIC確認

# nmcli

# ip addr

# ifconfig

など

CentOS 7

# vi /etc/sysconfig/network-script/ifcnf-enp0s3

ifcnf-enp0s3

ONBOOT = yes # 有効になってなければ変更する

BOOTPROTO = none # 書き換え

IPADDR = 192.168.3.2 # 以下追記

NETMASK = 255.255.255.0

GATEWAY = 192.168.3.1

DNS1 = 192.168.3.1
# systemctl restart network.service

;上記でエラーが出た場合は接続していないネットワークカードの ONBOOT を no にすると改善される場合がある。

 

Ubuntu 20.04

# vi /etc/netplan/99-netcfg.yaml

99-netcfg.yaml

network:
  version: 2
  ethernets:
    enp0s3:
      addresses: [192.168.3.2/24]
      gateway4: 192.168.3.1
      nameservers:
        addresses: [192.168.3.1]
        search: []
      optional: true
# mv 00-installer-config.yaml 00-installer-config.yaml.dis
# netplan apply

Kali-Linux

DebianベースなのでUbuntu20.04と同じようにできると思いきやできなかった。

# vi /etc/network/interface

interface

allow-hotplug eth0
iface eth0 inet static
  address 192.168.3.2
  netmask 255.255.255.0
  gateway 192.168.3.1
  dns-nameservers 192.168.3.1
# systemctl restart networking.service
# ifup eth0

 

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?