UbuntuでOS再起動後もiptablesの設定を有効化させる方法

概要

UbuntuでOS再起動後iptablesの情報が読み込まれずハマった。

インストール

apt-get install iptables-persistent

このパッケージを入れると設定ファイルに書き出してくれる。

依存関係で netfilter-persistent パッケージがインストールされる。

/etc/iptables/rules.v4

に書き出される。

保存

service netfilter-persistent save


読み込み

service netfilter-persistent reload


デーモンの起動

systemctl status netfilter-persistent.service


自動起動設定

systemctl enable netfilter-persistent.service


依存関係

# apt-cache depends netfilter-persistent
netfilter-persistent
  Depends: lsb-base
  Depends: init-system-helpers
  Breaks: iptables-persistent
  Suggests: iptables-persistent
  Replaces: iptables-persistent


# apt-cache rdepends netfilter-persistent
netfilter-persistent
Reverse Depends:
  iptables-persistent


パッケージの中身

# dpkg -L iptables-persistent
/.
/etc
/etc/iptables
/usr
/usr/share
/usr/share/doc
/usr/share/doc/iptables-persistent
/usr/share/doc/iptables-persistent/copyright
/usr/share/netfilter-persistent
/usr/share/netfilter-persistent/plugins.d
/usr/share/netfilter-persistent/plugins.d/15-ip4tables
/usr/share/netfilter-persistent/plugins.d/25-ip6tables
/usr/share/doc/iptables-persistent/README
/usr/share/doc/iptables-persistent/changelog.gz


# dpkg -L netfilter-persistent
/.
/etc
/etc/default
/etc/default/netfilter-persistent
/etc/init.d
/etc/init.d/netfilter-persistent
/lib
/lib/systemd
/lib/systemd/system
/lib/systemd/system/netfilter-persistent.service
/usr
/usr/sbin
/usr/sbin/netfilter-persistent
/usr/share
/usr/share/doc
/usr/share/doc/netfilter-persistent
/usr/share/doc/netfilter-persistent/README
/usr/share/doc/netfilter-persistent/changelog.gz
/usr/share/doc/netfilter-persistent/copyright
/usr/share/man
/usr/share/man/man8
/usr/share/man/man8/netfilter-persistent.8.gz
/usr/share/netfilter-persistent
/usr/share/netfilter-persistent/plugins.d


rsyncの時ユーザ名を明示しないと出るエラー

rsyncを行う際にユーザ名を指定しないとエラーが出ることがある。
その際はユーザを指定することでrsyncが実行出来る。

エラー

$ rsync -avz example.com:/tmp/ .
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
           [-D [bind_address:]port] [-e escape_char] [-F configfile]
           [-I pkcs11] [-i identity_file]
           [-L [bind_address:]port:host:hostport]
           [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
           [-R [bind_address:]port:host:hostport] [-S ctl_path]
           [-W host:port] [-w local_tun[:remote_tun]]
           [user@]hostname [command]
rsync: connection unexpectedly closed (0 bytes received so far) [receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(600) [receiver=3.0.6]


ユーザ名を指定

$ rsync -avz tsuokawa@example.com:/tmp/ .
The authenticity of host 'example.com (10.0.0.1)' can't be established.
RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.

Gitの設定を仕事用、個人用で分ける

概要

1台のPCで仕事用、個人用それぞれのGitリポジトリに接続する場合、
git configの設定を都度行うのは面倒です。

そこで~/.gitconfigディレクトリ毎に仕事用、個人用の設定を行うことで、

と自動で行うことが出来ます。

メールアドレス ディレクト
仕事 tsunokawa@example.com ~/work/以下
個人 tsunokawa@example.net ~/personal/以下


~/.gitconfig

ここで全体の設定を行います。

# グローバル設定
[user]
    name = Kenichi Tsunokawa
    email = tsunokawa@example.com

# ~/work/以下の場合仕事用に設定を行う。
# 仕事用設定ファイルを指定
[includeIf "gitdir:~/work/"]
    path = ~/.gitconfig-work

# ~/personal/以下の場合仕事用に設定を行う。
# 個人用設定ファイルを指定
[includeIf "gitdir:~/personal/"]
    path = ~/.gitconfig-personal


.gitconfig-work

~/work/以下にcloneしたリポジトリの場合の設定を記述します。

[user]
    name = Kenichi Tsunokawa
    email = tsunokawa@example.com


.gitconfig-personal

~/personal/以下にcloneしたリポジトリの場合の設定を記述します。

[user]
    name = Kenichi Tsunokawa
    email = tsunokawa@example.net