LoginSignup
2
2

More than 3 years have passed since last update.

CentOS8でlegacyなiptablesを使用する。

Last updated at Posted at 2020-04-01

CentOS8ではFireWallのバックエンドがnftableに変わっているためkubernetesのCNIが正常に動作しない。
(calicoはちょっとマニュフェスト修正すれば動く)
またCentOS8ではlegacyなiptablesのコマンド(xtables-legacy-multi)が存在しない.
そのため、ソースパッケージからコンパイルしてlegacyなiptablesのインストールを行う。

※正直こんなことするより素直に別ディストリビューション(Ubuntuとか)でkubernetes動かした方がいいです。

2020/04/01
yumのrepoのファイルパスに誤記があったので修正
コンパイルに必要なパッケージをインストールに不足があったので追記G


1.dnf(yum)のソースリポジトリの有効化

CentOS8.1の場合baseurlの先が存在しないので合わせて修正も行う。

vi /etc/yum.repos.d/CentOS-Sources.repo

以下の様に変更

・変更前

[BaseOS-source]
name=CentOS-$releasever - BaseOS Sources
baseurl=http://vault.centos.org/$contentdir/$releasever/BaseOS/Source/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

#AppStream
[AppStream-source]
name=CentOS-$releasever - AppStream Sources
baseurl=http://vault.centos.org/$contentdir/$releasever/AppStream/Source/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

#additional packages that may be useful
[extras-source]
name=CentOS-$releasever - Extras Sources
baseurl=http://vault.centos.org/$contentdir/$releasever/extras/Source/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

#additional packages that extend functionality of existing packages
[centosplus-source]
name=CentOS-$releasever - Plus Sources
baseurl=http://vault.centos.org/$contentdir/$releasever/centosplus/Source/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

・変更後

[BaseOS-source]
name=CentOS-$releasever - BaseOS Sources
#baseurl=http://vault.centos.org/$contentdir/$releasever/BaseOS/Source/
baseurl=http://vault.centos.org/8.1.1911/BaseOS/Source/
gpgcheck=1
#enabled=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

#AppStream
[AppStream-source]
name=CentOS-$releasever - AppStream Sources
#baseurl=http://vault.centos.org/$contentdir/$releasever/AppStream/Source/
baseurl=http://vault.centos.org/8.1.1911/AppStream/Source/
gpgcheck=1
#enabled=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

#additional packages that may be useful
[extras-source]
name=CentOS-$releasever - Extras Sources
#baseurl=http://vault.centos.org/$contentdir/$releasever/extras/Source/
baseurl=http://vault.centos.org/8.1.1911/extras/Source/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

#additional packages that extend functionality of existing packages
[centosplus-source]
name=CentOS-$releasever - Plus Sources
baseurl=http://vault.centos.org/$contentdir/$releasever/centosplus/Source/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

2.dnf(yum)のPowerToolsリポジトリの有効化

vi /etc/yum.repos.d/CentOS-PowerTools.repo

以下の様に変更

・変更前

[PowerTools]
name=CentOS-$releasever - PowerTools
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=PowerTools&infra=$infra
#baseurl=http://mirror.centos.org/$contentdir/$releasever/PowerTools/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

・変更後

[PowerTools]
name=CentOS-$releasever - PowerTools
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=PowerTools&infra=$infra
#baseurl=http://mirror.centos.org/$contentdir/$releasever/PowerTools/$basearch/os/
gpgcheck=1
#enabled=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

3.開発環境のインストール

dnf groupinstall "RPM Development Tools" "Development Tools"

4.コンパイルに必要なパッケージをインストール

dnf install libpcap-devel libselinux-devel libmnl-devel libnetfilter_conntrack-devel libnfnetlink-devel libnftnl

5.yum-utilsのインストール

dnf install yum-utils

6.libnftnlのソースパッケージをダウンロード

iptablesのrpmパッケージを作成するにはlibnftnl-develが必要であるがCentOS8には存在しないパッケージのためソースをダウンロードして、この後の手順でコンパイル、インストールを行う。
存在しない理由の詳細は一番下の参考を参照

cd ~/
yumdownloader --source libnftnl

7.libnftnlのrpmパッケージ作成

※ソースパッケージ名は2020/04/01時点のバージョン

cd ~/
rpm -ivh libnftnl-1.1.1-4.el8.src.rpm
cd ~/rpmbuild/SPECS/
rpmbuild -bb libnftnl.spec

8.libnftnl-develのインストール

rpm -ivh ~/rpmbuild/RPMS/x86_64/libnftnl-devel-1.1.1-4.el8.x86_64.rpm

9.iptablesのソースパッケージをダウンロード

cd ~/
yumdownloader --source iptables

10.iptablesのSPECファイルの修正

※ソースパッケージ名は2020/04/01時点のバージョン

cd ~/
rpm -ivh iptables-1.8.2-16.el8.src.rpm
cd ~/rpmbuild/SPECS/
vi iptables.spec

以下のように修正する。

・10行目あたり

Release: 16%{?dist}

 ↓

Release: 16_include_legacy%{?dist}

・301行目あたり

# drop all legacy tools
rm -f %{buildroot}%{_sbindir}/*legacy*
rm -f %{buildroot}%{_bindir}/iptables-xml
rm -f %{buildroot}%{_mandir}/man1/iptables-xml*
rm -f %{buildroot}%{_mandir}/man8/xtables-legacy*

 ↓

# drop all legacy tools
#rm -f %{buildroot}%{_sbindir}/*legacy*
#rm -f %{buildroot}%{_bindir}/iptables-xml
#rm -f %{buildroot}%{_mandir}/man1/iptables-xml*
#rm -f %{buildroot}%{_mandir}/man8/xtables-legacy*

・374~407行目あたり

%files
   :
   :
%{_libdir}/xtables/libarpt*
%{_libdir}/xtables/libebt*
%{_libdir}/xtables/libipt*
%{_libdir}/xtables/libip6t*
%{_libdir}/xtables/libxt*

 ↓

%files
   :
   :
%{_libdir}/xtables/libarpt*
%{_libdir}/xtables/libebt*
%{_libdir}/xtables/libipt*
%{_libdir}/xtables/libip6t*
%{_libdir}/xtables/libxt*
%{_sbindir}/*legacy*
%{_bindir}/iptables-xml
%doc %{_mandir}/man1/iptables-xml*
%doc %{_mandir}/man8/xtables-legacy*

11.iptablesのrpmパッケージ作成

rpmbuild -bb iptables.spec

12.iptablesのパッケージ更新

rpm -Fvh ~/rpmbuild/RPMS/x86_64/iptables-*

13.シンボリックリンクの変更

iptablesのリンク先をxtables-nft-multiからxtables-legacy-multiに変更

ln -nfs xtables-legacy-multi /usr/sbin/iptables

14.確認

iptables -V

以下のようにlegacyと表示されていること

iptables v1.8.2 (legacy)

15.dnf(yum)によるiptablesのパッケージの自動更新抑止

vi /etc/yum.conf

以下を設定する。

exclude=iptables*

16.libnftnl-develの削除

CentOS8には本来存在しないパッケージのためlibnftnl-develは削除する。
※dnf(yum)による更新時に依存関係でエラーが出る可能性があるため

rpm -evh libnftnl-devel

参考

Does RHEL8 provides legacy iptables(xtables-legacy-multi)?
https://access.redhat.com/solutions/4377321

Bug 1711361 - libnftnl-devel package not available to install via dnf install
https://bugzilla.redhat.com/show_bug.cgi?id=1711361

2
2
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
2
2