Help us understand the problem. What is going on with this article?

アプリの設定を変えずにポート番号を柔軟に変更する

More than 3 years have passed since last update.

ちょっと外向けにポート番号を変えたいけど元のアプリケーションは変更したくない場合、iptablesのネットワークアドレス変換機能(NAT)を使うと便利です。

例) TCPの8000番ポートで公開されているサービスを80番ポートでのアクセスも追加(元の8000番ポートでもアクセス可)

sudo iptables -t nat -I PREROUTING -p tcp       --dport 80 -j REDIRECT --to-ports 8000
sudo iptables -t nat -I OUTPUT     -p tcp -o lo --dport 80 -j REDIRECT --to-ports 8000

設定を表示するとこんな感じです。

% sudo iptables -L -t nat
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 8000

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 8000

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
tadokoro
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away