2016-12-01 143 views
-2

我需要將端口8080重定向到我的Linux服務器上的端口80。 我的問題是一樣的: https://askubuntu.com/a/579540Firewalld:將端口80重定向到8080並使其在本地機器上工作

唯一的區別是,我沒有iptables - 有沒有辦法與firewalld做到這一點?

編輯:現在我知道firewalld使用iptables和命令可以通過firewalld使用被傳遞到iptables的:

firewall-cmd [--permanent] --direct --add-rule { ipv4 | ipv6 | eb } <table> <chain> <priority> <args> 

我:

  • HTTP服務器的端口8080
  • 運行
  • 端口80重定向到8080在firewalld(區公衆)
  • 客戶端從其他計算機訪問通過GH 80端口可以得到
  • 我可以在同一臺計算機,在服務器運行的是

訪問端口8080上的服務器我想也是HTTP服務器:

  • 訪問從同一臺計算機,在服務器運行的是

端口80上的服務器我想:

  • 添加接口 「LO」,以同樣的方式作爲區 「公共」

區 「公共」 配置區 「公共」

  • 配置區 「可信」:

    <zone> 
        <short>Public</short> 
        <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description> 
        <service name="snmp"/> 
        <service name="http"/> 
        <service name="ssh"/> 
        <service name="https"/> 
        <icmp-block name="redirect"/> 
        <icmp-block name="router-solicitation"/> 
        <icmp-block name="parameter-problem"/> 
        <icmp-block name="router-advertisement"/> 
        <forward-port to-port="8080" protocol="tcp" port="80"/> 
    </zone> 
    

    錯誤:

    #wget "192.168.100.42:80" 
    --2016-12-01 16:02:29-- http://192.168.100.42/ 
    Connecting to 192.168.100.42:80... failed: Connection refused. 
    
    #wget "192.168.100.42:8080" 
    --2016-12-01 16:06:37-- http://192.168.100.42:8080/ 
    Connecting to 192.168.100.42:8080... connected. 
    HTTP request sent, awaiting response... 302 Found 
    ... 
    HTTP request sent, awaiting response... 302 Found 
    ... 
    HTTP request sent, awaiting response... 302 Found 
    ... 
    HTTP request sent, awaiting response... 200 OK 
    Length: unspecified [text/html] 
    Saving to: ‘index.html’ 
    ... 
    2016-12-01 16:06:37 (69.8 MB/s) - ‘index.html’ saved [4785] 
    
    #wget "localhost:80" 
    --2016-12-01 16:02:12-- http://localhost/ 
    Resolving localhost (localhost)... 127.0.0.1, ::1 
    Connecting to localhost (localhost)|127.0.0.1|:80... failed: Connection refused. 
    Connecting to localhost (localhost)|::1|:80... failed: Network is unreachable. 
    
    #wget "localhost:8080" 
    --2016-12-01 16:06:29-- http://localhost:8080/ 
    Resolving localhost (localhost)... 127.0.0.1, ::1 
    Connecting to localhost (localhost)|127.0.0.1|:8080... failed: Connection refused. 
    Connecting to localhost (localhost)|::1|:8080... failed: Network is unreachable. 
    

    編輯:解決方案: 服務器根本沒有監聽回送接口。

  • 回答

    1

    服務器沒有監聽loopback接口上。

    +0

    請改善此答案;它缺乏足夠的細節。我有一個新的CentOS 7.2安裝(取代舊的Ubuntu系統); firewalld對我來說是新的。我沒有運行httpd,只是運行在8180上的Tomcat 8,從80-> 8180的防火牆端口轉發。在公共區域工作良好,並且端口8180也適用於本地主機,但端口轉發不能。 'firewall-config'列出* no *「接口」。netstap顯示 'tcp6 0 0 ::: 8180 ::: * LISTEN -' – djb

    0

    取得該職位Firewall。修改您的IPS本地網絡和服務器:

    創建/etc/init.d/boot.d中一個iptables.sh,使用chmod + x和運行

    # NOMENCLATURE 
    internet=eth0  # interface of internet source 
    lan=eth1   # interface of local network 
    local=192.168.1.0 # your local network 
    netmask=24  # netmask of your local network 
    iptables=/sbin/iptables 
    
    # Zero all packets and counters 
    $iptables -F 
    $iptables -X 
    $iptables -t nat -F 
    $iptables -t nat -X 
    $iptables -t mangle -F 
    $iptables -t mangle -X 
    $iptables -t raw -F 
    $iptables -t raw -X 
    $iptables -t security -F 
    $iptables -t security -X 
    $iptables -Z 
    $iptables -t nat -Z 
    $iptables -t mangle -Z 
    
    # Global Policies (DROP or ACCEPT) 
    $iptables -P INPUT ACCEPT 
    $iptables -P OUTPUT ACCEPT 
    $iptables -P FORWARD ACCEPT 
    $iptables -t nat -P PREROUTING ACCEPT 
    $iptables -t nat -P POSTROUTING ACCEPT 
    $iptables -t nat -P OUTPUT ACCEPT 
    $iptables -t mangle -P PREROUTING ACCEPT 
    $iptables -t mangle -P INPUT ACCEPT 
    $iptables -t mangle -P FORWARD ACCEPT 
    $iptables -t mangle -P OUTPUT ACCEPT 
    $iptables -t mangle -P POSTROUTING ACCEPT 
    
    # LOOPBACK 
    $iptables -A INPUT -p all -i lo -j ACCEPT 
    $iptables -A INPUT -s 192.168.1.10 -j ACCEPT 
    $iptables -A OUTPUT -p all -o lo -j ACCEPT 
    $iptables -A OUTPUT -p all -s 127.0.0.1 -j ACCEPT 
    $iptables -t mangle -A PREROUTING -p all -i lo -j ACCEPT 
    $iptables -t mangle -A PREROUTING -p all -s 127.0.0.1 -j ACCEPT 
    $iptables -t nat -A PREROUTING -p all -i lo -j ACCEPT 
    
    # IP forward rules 
    echo 1 > /proc/sys/net/ipv4/ip_forward 
    
    # MASQUERADE 
    $iptables -t nat -A POSTROUTING -s $local/$netmask -o $internet -j MASQUERADE 
    
    $iptables -A OUTPUT -p udp --dport 53 -j DROP 
    $iptables -A INPUT -p udp --sport 53 -j DROP 
    $iptables -A FORWARD -p udp --dport 53 -j DROP 
    
    # LAN ---> PROXY <--- INTERNET 
    $iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT 
    $iptables -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT 
    $iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT 
    
    # TRANSPARENT RULES 
    $iptables -t nat -A PREROUTING -i $lan -p tcp --dport 80 -j REDIRECT --to-port 8080 
    $iptables -A INPUT -i $lan -p tcp --dport 8080 -j ACCEPT 
    $iptables -A FORWARD -i $lan -p tcp -m multiport --dports 80,8080,443 -o $internet -j ACCEPT